From f1d42fe787c20ff2d62b0aab00874fe9c79af352 Mon Sep 17 00:00:00 2001 From: marmeladema Date: Mon, 14 Oct 2019 00:36:20 +0100 Subject: Use urllib from six module in order to be compatible with Python3 --- python/servo/util.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'python/servo/util.py') diff --git a/python/servo/util.py b/python/servo/util.py index 818240d39e6..f51b1f12252 100644 --- a/python/servo/util.py +++ b/python/servo/util.py @@ -20,7 +20,7 @@ import StringIO import sys import time import zipfile -import urllib2 +import six.moves.urllib as urllib try: @@ -101,10 +101,10 @@ def download(desc, src, writer, start_byte=0): dumb = (os.environ.get("TERM") == "dumb") or (not sys.stdout.isatty()) try: - req = urllib2.Request(src) + req = urllib.request.Request(src) if start_byte: - req = urllib2.Request(src, headers={'Range': 'bytes={}-'.format(start_byte)}) - resp = urllib2.urlopen(req, **get_urlopen_kwargs()) + req = urllib.request.Request(src, headers={'Range': 'bytes={}-'.format(start_byte)}) + resp = urllib.request.urlopen(req, **get_urlopen_kwargs()) fsize = None if resp.info().getheader('Content-Length'): @@ -136,13 +136,13 @@ def download(desc, src, writer, start_byte=0): if not dumb: print() - except urllib2.HTTPError, e: + except urllib.error.HTTPError, e: print("Download failed ({}): {} - {}".format(e.code, e.reason, src)) if e.code == 403: print("No Rust compiler binary available for this platform. " "Please see https://github.com/servo/servo/#prerequisites") sys.exit(1) - except urllib2.URLError, e: + except urllib.error.URLError, e: print("Error downloading {}: {}. The failing URL was: {}".format(desc, e.reason, src)) sys.exit(1) except socket_error, e: -- cgit v1.2.3 From 02cfb4f49e070fc51c04d5d1f7092ae3ca4621bc Mon Sep 17 00:00:00 2001 From: marmeladema Date: Mon, 14 Oct 2019 00:40:22 +0100 Subject: Fix except statement in order to be compatible with Python3 --- python/servo/util.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'python/servo/util.py') diff --git a/python/servo/util.py b/python/servo/util.py index f51b1f12252..e30f377db66 100644 --- a/python/servo/util.py +++ b/python/servo/util.py @@ -136,16 +136,16 @@ def download(desc, src, writer, start_byte=0): if not dumb: print() - except urllib.error.HTTPError, e: + except urllib.error.HTTPError as e: print("Download failed ({}): {} - {}".format(e.code, e.reason, src)) if e.code == 403: print("No Rust compiler binary available for this platform. " "Please see https://github.com/servo/servo/#prerequisites") sys.exit(1) - except urllib.error.URLError, e: + except urllib.error.URLError as e: print("Error downloading {}: {}. The failing URL was: {}".format(desc, e.reason, src)) sys.exit(1) - except socket_error, e: + except socket_error as e: print("Looks like there's a connectivity issue, check your Internet connection. {}".format(e)) sys.exit(1) except KeyboardInterrupt: -- cgit v1.2.3 From bf66a08c023e0f8fe93ad1a41dae90e0ca12c002 Mon Sep 17 00:00:00 2001 From: marmeladema Date: Mon, 14 Oct 2019 18:19:07 +0100 Subject: Fix StringIO module import to be compatible with Python3 --- python/servo/util.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'python/servo/util.py') diff --git a/python/servo/util.py b/python/servo/util.py index e30f377db66..38127093ae8 100644 --- a/python/servo/util.py +++ b/python/servo/util.py @@ -16,7 +16,7 @@ import platform import shutil from socket import error as socket_error import stat -import StringIO +from io import BytesIO import sys import time import zipfile @@ -154,7 +154,7 @@ def download(desc, src, writer, start_byte=0): def download_bytes(desc, src): - content_writer = StringIO.StringIO() + content_writer = BytesIO() download(desc, src, content_writer) return content_writer.getvalue() -- cgit v1.2.3