From a9e07efecdc3c949b93b4f1959fb57e51b3ef71c Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Mon, 10 Sep 2018 19:47:53 +0530 Subject: [PATCH] The setup package now imports under python 3 --- setup/upload.py | 9 +++++---- src/polyglot/urllib.py | 15 +++++++++++++++ 2 files changed, 20 insertions(+), 4 deletions(-) create mode 100644 src/polyglot/urllib.py diff --git a/setup/upload.py b/setup/upload.py index 634e41c67f..b9687f2213 100644 --- a/setup/upload.py +++ b/setup/upload.py @@ -6,10 +6,11 @@ __license__ = 'GPL v3' __copyright__ = '2009, Kovid Goyal ' __docformat__ = 'restructuredtext en' -import os, subprocess, hashlib, shutil, glob, stat, sys, time, urllib2, urllib, json, httplib +import os, subprocess, hashlib, shutil, glob, stat, sys, time, json from subprocess import check_call from tempfile import NamedTemporaryFile, mkdtemp, gettempdir from zipfile import ZipFile +from polyglot.urllib import urlopen, urlencode if __name__ == '__main__': d = os.path.dirname @@ -180,14 +181,14 @@ def upload_to_fosshub(): }] } # print(json.dumps(jq, indent=2)) - rq = urllib2.urlopen( + rq = urlopen( 'https://www.fosshub.com/JSTools/uploadJson', - urllib.urlencode({ + urlencode({ 'content': json.dumps(jq) }) ) resp = rq.read() - if rq.getcode() != httplib.OK: + if rq.getcode() != 200: raise SystemExit( 'Failed to upload to fosshub, with HTTP error code: %d and response: %s' % (rq.getcode(), resp) diff --git a/src/polyglot/urllib.py b/src/polyglot/urllib.py new file mode 100644 index 0000000000..46bc7ed883 --- /dev/null +++ b/src/polyglot/urllib.py @@ -0,0 +1,15 @@ +#!/usr/bin/env python2 +# vim:fileencoding=utf-8 +# License: GPL v3 Copyright: 2018, Kovid Goyal + +from __future__ import absolute_import, division, print_function, unicode_literals + + +from polyglot.builtins import is_py3 + +if is_py3: + from urllib.request import urlopen # noqa + from urllib.parse import urlencode # noqa +else: + from urllib import urlencode # noqa + from urllib2 import urlopen # noqa