Clone of https://github.com/NixOS/nixpkgs.git (to stress-test knotserver)

Merge pull request #268420 from Samuel-Martineau/fix/pastebinit

pastebinit: fix deprecation warning and add darwin compatibility

authored by Arnout Engelen and committed by GitHub 48a75321 98b3b2ee

+86 -8
+6 -8
pkgs/tools/misc/pastebinit/default.nix
··· 1 - { lib, stdenv 1 + { lib 2 + , stdenv 2 3 , fetchurl 3 4 , fetchpatch 4 5 , python3 5 6 }: 6 - 7 7 stdenv.mkDerivation rec { 8 8 version = "1.5"; 9 9 pname = "pastebinit"; ··· 21 21 22 22 patches = [ 23 23 # Required to allow pastebinit 1.5 to run on Python 3.8 24 - (fetchpatch { 25 - name = "use-distro-module.patch"; 26 - url = "https://bazaar.launchpad.net/~arnouten/pastebinit/python38/diff/264?context=3"; 27 - sha256 = "1gp5inp4xald65xbb7fc5aqq5s2fhw464niwjjja9anqyp3zhawj"; 28 - }) 24 + ./use-distro-module.patch 25 + # Required to remove the deprecation warning of FancyURLopener 26 + ./use-urllib-request.patch 29 27 # Required because pastebin.com now redirects http requests to https 30 28 (fetchpatch { 31 29 name = "pastebin-com-https.patch"; ··· 47 45 description = "A software that lets you send anything you want directly to a pastebin from the command line"; 48 46 maintainers = with maintainers; [ raboof ]; 49 47 license = licenses.gpl2; 50 - platforms = platforms.linux; 48 + platforms = platforms.linux ++ lib.platforms.darwin; 51 49 }; 52 50 }
+14
pkgs/tools/misc/pastebinit/use-distro-module.patch
··· 1 + === modified file 'pastebinit' 2 + --- pastebinit 2018-07-04 00:46:08 +0000 3 + +++ pastebinit 2020-11-13 14:21:11 +0000 4 + @@ -38,8 +38,8 @@ 5 + 6 + # Now try to override it with a distributor pastebin 7 + try: 8 + - import platform 9 + - release = platform.linux_distribution()[0].lower() 10 + + import distro 11 + + release = distro.id() 12 + if release == 'debian': 13 + defaultPB = "paste.debian.net" 14 + elif release == 'fedora':
+66
pkgs/tools/misc/pastebinit/use-urllib-request.patch
··· 1 + === modified file 'pastebinit' 2 + --- pastebinit 2018-07-04 00:46:08 +0000 3 + +++ pastebinit 2020-11-13 14:21:11 +0000 4 + @@ -23,15 +23,9 @@ 5 + from __future__ import print_function 6 + 7 + import sys 8 + -if sys.version[0] == "2": 9 + - from ConfigParser import NoOptionError 10 + - from ConfigParser import SafeConfigParser as ConfigParser 11 + - from urllib import urlencode 12 + - from urllib import FancyURLopener 13 + -else: 14 + - from configparser import ConfigParser, NoOptionError 15 + - from urllib.parse import urlencode 16 + - from urllib.request import FancyURLopener 17 + +from configparser import ConfigParser, NoOptionError 18 + +from urllib.parse import urlencode 19 + +from urllib.request import urlopen, Request 20 + 21 + # Set the default pastebin 22 + defaultPB = "pastebin.com" 23 + @@ -72,13 +66,6 @@ try: 24 + version = "1.5" 25 + configfile = os.path.expanduser("~/.pastebinit.xml") 26 + 27 + - # Custom urlopener to handle 401's 28 + - class pasteURLopener(FancyURLopener): 29 + - version = "Pastebinit v%s" % version 30 + - 31 + - def http_error_401(self, url, fp, errcode, errmsg, headers, data=None): 32 + - return None 33 + - 34 + def preloadPastebins(): 35 + # Check several places for config files: 36 + # - global config in /etc/pastebin.d 37 + @@ -410,12 +397,18 @@ try: 38 + else: 39 + post_format = 'standard' 40 + 41 + - url_opener = pasteURLopener() 42 + + request = Request( 43 + + fetch_url, 44 + + method="POST", 45 + + headers={ 46 + + 'User-Agent': "Pastebinit v%s" % version 47 + + } 48 + + ) 49 + 50 + if post_format == 'json': 51 + if json: 52 + params = json.dumps(params) 53 + - url_opener.addheader('Content-type', 'text/json') 54 + + request.add_header('Content-type', 'text/json') 55 + else: 56 + print(_("Could not find any json library."), file=sys.stderr) 57 + sys.exit(1) 58 + @@ -428,7 +421,7 @@ try: 59 + print("POSTing to: %s\nParams: %s" % ( 60 + fetch_url, str(params)), file=sys.stderr) 61 + try: 62 + - page = url_opener.open(fetch_url, params) 63 + + page = urlopen(request, params.encode("utf-8")) 64 + except Exception as e: 65 + print(_("Failed to contact the server: %s") % e, file=sys.stderr) 66 + sys.exit(1)