pastebinit: fix deprecation warning and add darwin compatibility
This commit is contained in:
parent
a5fcd81011
commit
3f18b3cf10
3 changed files with 86 additions and 8 deletions
|
@ -1,9 +1,9 @@
|
|||
{ lib, stdenv
|
||||
{ lib
|
||||
, stdenv
|
||||
, fetchurl
|
||||
, fetchpatch
|
||||
, python3
|
||||
}:
|
||||
|
||||
stdenv.mkDerivation rec {
|
||||
version = "1.5";
|
||||
pname = "pastebinit";
|
||||
|
@ -21,11 +21,9 @@ stdenv.mkDerivation rec {
|
|||
|
||||
patches = [
|
||||
# Required to allow pastebinit 1.5 to run on Python 3.8
|
||||
(fetchpatch {
|
||||
name = "use-distro-module.patch";
|
||||
url = "https://bazaar.launchpad.net/~arnouten/pastebinit/python38/diff/264?context=3";
|
||||
sha256 = "1gp5inp4xald65xbb7fc5aqq5s2fhw464niwjjja9anqyp3zhawj";
|
||||
})
|
||||
./use-distro-module.patch
|
||||
# Required to remove the deprecation warning of FancyURLopener
|
||||
./use-urllib-request.patch
|
||||
# Required because pastebin.com now redirects http requests to https
|
||||
(fetchpatch {
|
||||
name = "pastebin-com-https.patch";
|
||||
|
@ -47,6 +45,6 @@ stdenv.mkDerivation rec {
|
|||
description = "A software that lets you send anything you want directly to a pastebin from the command line";
|
||||
maintainers = with maintainers; [ raboof ];
|
||||
license = licenses.gpl2;
|
||||
platforms = platforms.linux;
|
||||
platforms = platforms.linux ++ lib.platforms.darwin;
|
||||
};
|
||||
}
|
||||
|
|
14
pkgs/tools/misc/pastebinit/use-distro-module.patch
Normal file
14
pkgs/tools/misc/pastebinit/use-distro-module.patch
Normal file
|
@ -0,0 +1,14 @@
|
|||
=== modified file 'pastebinit'
|
||||
--- pastebinit 2018-07-04 00:46:08 +0000
|
||||
+++ pastebinit 2020-11-13 14:21:11 +0000
|
||||
@@ -38,8 +38,8 @@
|
||||
|
||||
# Now try to override it with a distributor pastebin
|
||||
try:
|
||||
- import platform
|
||||
- release = platform.linux_distribution()[0].lower()
|
||||
+ import distro
|
||||
+ release = distro.id()
|
||||
if release == 'debian':
|
||||
defaultPB = "paste.debian.net"
|
||||
elif release == 'fedora':
|
66
pkgs/tools/misc/pastebinit/use-urllib-request.patch
Normal file
66
pkgs/tools/misc/pastebinit/use-urllib-request.patch
Normal file
|
@ -0,0 +1,66 @@
|
|||
=== modified file 'pastebinit'
|
||||
--- pastebinit 2018-07-04 00:46:08 +0000
|
||||
+++ pastebinit 2020-11-13 14:21:11 +0000
|
||||
@@ -23,15 +23,9 @@
|
||||
from __future__ import print_function
|
||||
|
||||
import sys
|
||||
-if sys.version[0] == "2":
|
||||
- from ConfigParser import NoOptionError
|
||||
- from ConfigParser import SafeConfigParser as ConfigParser
|
||||
- from urllib import urlencode
|
||||
- from urllib import FancyURLopener
|
||||
-else:
|
||||
- from configparser import ConfigParser, NoOptionError
|
||||
- from urllib.parse import urlencode
|
||||
- from urllib.request import FancyURLopener
|
||||
+from configparser import ConfigParser, NoOptionError
|
||||
+from urllib.parse import urlencode
|
||||
+from urllib.request import urlopen, Request
|
||||
|
||||
# Set the default pastebin
|
||||
defaultPB = "pastebin.com"
|
||||
@@ -72,13 +66,6 @@ try:
|
||||
version = "1.5"
|
||||
configfile = os.path.expanduser("~/.pastebinit.xml")
|
||||
|
||||
- # Custom urlopener to handle 401's
|
||||
- class pasteURLopener(FancyURLopener):
|
||||
- version = "Pastebinit v%s" % version
|
||||
-
|
||||
- def http_error_401(self, url, fp, errcode, errmsg, headers, data=None):
|
||||
- return None
|
||||
-
|
||||
def preloadPastebins():
|
||||
# Check several places for config files:
|
||||
# - global config in /etc/pastebin.d
|
||||
@@ -410,12 +397,18 @@ try:
|
||||
else:
|
||||
post_format = 'standard'
|
||||
|
||||
- url_opener = pasteURLopener()
|
||||
+ request = Request(
|
||||
+ fetch_url,
|
||||
+ method="POST",
|
||||
+ headers={
|
||||
+ 'User-Agent': "Pastebinit v%s" % version
|
||||
+ }
|
||||
+ )
|
||||
|
||||
if post_format == 'json':
|
||||
if json:
|
||||
params = json.dumps(params)
|
||||
- url_opener.addheader('Content-type', 'text/json')
|
||||
+ request.add_header('Content-type', 'text/json')
|
||||
else:
|
||||
print(_("Could not find any json library."), file=sys.stderr)
|
||||
sys.exit(1)
|
||||
@@ -428,7 +421,7 @@ try:
|
||||
print("POSTing to: %s\nParams: %s" % (
|
||||
fetch_url, str(params)), file=sys.stderr)
|
||||
try:
|
||||
- page = url_opener.open(fetch_url, params)
|
||||
+ page = urlopen(request, params.encode("utf-8"))
|
||||
except Exception as e:
|
||||
print(_("Failed to contact the server: %s") % e, file=sys.stderr)
|
||||
sys.exit(1)
|
Loading…
Reference in a new issue