Skip to content

Commit

Permalink
pastebinit: fix warnings
Browse files Browse the repository at this point in the history
Reported in #4112.
  • Loading branch information
Leonid Plyushch committed Jul 27, 2019
1 parent 48770a0 commit bd78c76
Show file tree
Hide file tree
Showing 2 changed files with 93 additions and 4 deletions.
1 change: 1 addition & 0 deletions packages/pastebinit/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ TERMUX_PKG_HOMEPAGE=https://launchpad.net/pastebinit
TERMUX_PKG_DESCRIPTION="Command-line pastebin client"
TERMUX_PKG_LICENSE="GPL-2.0"
TERMUX_PKG_VERSION=1.5
TERMUX_PKG_REVISION=1
TERMUX_PKG_SRCURL=https://launchpad.net/pastebinit/trunk/${TERMUX_PKG_VERSION}/+download/pastebinit-${TERMUX_PKG_VERSION}.tar.bz2
TERMUX_PKG_SHA256=42e5a84ce7e46825fb3b6478e11893fad357197327257e474bd0d3549f438457
TERMUX_PKG_DEPENDS="python"
Expand Down
96 changes: 92 additions & 4 deletions packages/pastebinit/pastebinit.patch
Original file line number Diff line number Diff line change
@@ -1,7 +1,64 @@
diff -u -r ../pastebinit-1.5/pastebinit ./pastebinit
--- ../pastebinit-1.5/pastebinit 2016-03-01 00:52:32.000000000 -0500
+++ ./pastebinit 2016-08-06 16:37:25.632592458 -0400
@@ -86,8 +86,8 @@
Changes:

= Do not set default pastbin url based on distribution used.

= Fix warning about deprecated methords in 'pasteURLopener' - applied patch from Debian.

= Fix paths to configuration directories.

diff -uNr pastebinit-1.5/pastebinit pastebinit-1.5.mod/pastebinit
--- pastebinit-1.5/pastebinit 2016-03-01 07:52:32.000000000 +0200
+++ pastebinit-1.5.mod/pastebinit 2019-07-27 14:05:27.571525242 +0300
@@ -27,28 +27,15 @@
from ConfigParser import NoOptionError
from ConfigParser import SafeConfigParser as ConfigParser
from urllib import urlencode
- from urllib import FancyURLopener
+ from urllib import request
else:
from configparser import ConfigParser, NoOptionError
from urllib.parse import urlencode
- from urllib.request import FancyURLopener
+ from urllib import request

# Set the default pastebin
defaultPB = "pastebin.com"

-# Now try to override it with a distributor pastebin
-try:
- import platform
- release = platform.linux_distribution()[0].lower()
- if release == 'debian':
- defaultPB = "paste.debian.net"
- elif release == 'fedora':
- defaultPB = "fpaste.org"
- elif release == 'ubuntu':
- defaultPB = "paste.ubuntu.com"
-except ImportError:
- pass
-
try:
import getopt
import gettext
@@ -72,12 +59,13 @@
version = "1.5"
configfile = os.path.expanduser("~/.pastebinit.xml")

- # Custom urlopener to handle 401's
- class pasteURLopener(FancyURLopener):
+ class PasteRequest(request.Request):
version = "Pastebinit v%s" % version

- def http_error_401(self, url, fp, errcode, errmsg, headers, data=None):
- return None
+ def __init__(self, *args, **opts):
+ super(PasteRequest, self).__init__(*args, **opts)
+ if 'User-agent' not in self.headers:
+ self.add_header('User-agent', self.version)

def preloadPastebins():
# Check several places for config files:
@@ -86,8 +74,8 @@
# - user's overrides in ~/.pastebin.d
# Files found later override files found earlier.
pastebind = {}
Expand All @@ -12,3 +69,34 @@ diff -u -r ../pastebinit-1.5/pastebinit ./pastebinit
os.path.expanduser('~/.pastebin.d'),
os.path.join(
os.path.dirname(
@@ -410,25 +398,25 @@
else:
post_format = 'standard'

- url_opener = pasteURLopener()
+ req = PasteRequest(fetch_url)

if post_format == 'json':
if json:
- params = json.dumps(params)
- url_opener.addheader('Content-type', 'text/json')
+ params = bytes(json.dumps(params), encoding='US-ASCII')
+ req.add_header('Content-type', 'text/json')
else:
print(_("Could not find any json library."), file=sys.stderr)
sys.exit(1)
else:
# Convert to a format usable with the HTML POST
- params = urlencode(params)
+ params = bytes(urlencode(params), encoding='US-ASCII')

# Send the informations and be redirected to the final page
if verbose:
print("POSTing to: %s\nParams: %s" % (
fetch_url, str(params)), file=sys.stderr)
try:
- page = url_opener.open(fetch_url, params)
+ page = request.urlopen(req, params)
except Exception as e:
print(_("Failed to contact the server: %s") % e, file=sys.stderr)
sys.exit(1)

0 comments on commit bd78c76

Please sign in to comment.