Package: pastebinit Version: 1.5-2 Severity: normal Tags: patch Hi,
After the upgrade to Pyton 3.7, pastebinit starts to emit 2 warnings. $ python3.6 /usr/bin/pastebinit /tmp/test.txt http://paste.debian.net/1055727/ $ python3.7 /usr/bin/pastebinit /tmp/test.txt /usr/bin/pastebinit:42: DeprecationWarning: dist() and linux_distribution() functions are deprecated in Python 3.5 release = platform.linux_distribution()[0].lower() /usr/bin/pastebinit:413: DeprecationWarning: pasteURLopener style of invoking requests is deprecated. Use newer urlopen functions/methods url_opener = pasteURLopener() http://paste.debian.net/1055728/ The attached patches silence the warnings for me. I only tested it against paste.debian.net, but I see no reason why any of the changes I did would be a problem for other sites. Note that the first patch adds a new dependency, so you also want something like this: diff -Nru pastebinit-1.5/debian/control pastebinit-1.5/debian/control --- pastebinit-1.5/debian/control 2018-04-15 12:04:53.000000000 -0300 +++ pastebinit-1.5/debian/control 2018-12-13 15:01:31.000000000 -0200 @@ -11,7 +11,7 @@ Package: pastebinit Architecture: all -Depends: python3, ${misc:Depends} +Depends: python3, python3-distro, ${misc:Depends} Breaks: bikeshed (<< 1.21) Replaces: bikeshed (<< 1.21) Description: command-line pastebin client -- System Information: Debian Release: buster/sid APT prefers unstable-debug APT policy: (500, 'unstable-debug'), (500, 'testing-debug'), (500, 'unstable'), (500, 'testing'), (1, 'experimental-debug'), (1, 'experimental') Architecture: amd64 (x86_64) Kernel: Linux 4.18.0-3-amd64 (SMP w/4 CPU cores) Locale: LANG=pt_BR.UTF-8, LC_CTYPE=pt_BR.UTF-8 (charmap=UTF-8), LANGUAGE=pt_BR:pt:en (charmap=UTF-8) Shell: /bin/sh linked to /usr/bin/dash Init: systemd (via /run/systemd/system) LSM: AppArmor: enabled Versions of packages pastebinit depends on: ii python3 3.7.1-2 ii python3-distro 1.3.0-1 pastebinit recommends no packages. pastebinit suggests no packages. -- no debconf information
Description: move away from deprecated platform functions The linux_distribution function from the platform has been deprecated in Python 3.5. `distro` is the natural sucessor, however it is a new dependency. Author: Antonio Terceiro <terce...@debian.org> --- a/pastebinit +++ b/pastebinit @@ -38,8 +38,8 @@ defaultPB = "pastebin.com" # Now try to override it with a distributor pastebin try: - import platform - release = platform.linux_distribution()[0].lower() + import distro + release = distro.linux_distribution(full_distribution_name=False)[0].lower() if release == 'debian': defaultPB = "paste.debian.net" elif release == 'fedora':
Description: update urlopen usage The URLOpener classes from the urllib.request are deprecated in Python 3.5. Replace them with a more modern usage of urlopen(). . Note that this patch removes the special handling of HTTP 401 ("Unauthorized"). Author: Antonio Terceiro <terce...@debian.org> --- a/pastebinit +++ b/pastebinit @@ -27,11 +27,11 @@ if sys.version[0] == "2": 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" @@ -72,12 +72,13 @@ try: 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: @@ -410,25 +411,25 @@ try: 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') + 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)
signature.asc
Description: PGP signature