aboutsummaryrefslogtreecommitdiffstats
path: root/python/servo/util.py
diff options
context:
space:
mode:
authorbors-servo <lbergstrom+bors@mozilla.com>2019-10-16 11:01:28 -0400
committerGitHub <noreply@github.com>2019-10-16 11:01:28 -0400
commit6d488f1be24c1b679931d6d02703f4a10759eb49 (patch)
tree03ca0c47f6317113825b329e7c25c46a2189156c /python/servo/util.py
parentbcd8c5e5970182e1eac7cfb1e4f2ab3e23139b1a (diff)
parent2b3f6a228929a0297f82fff18bfffa98707bb031 (diff)
downloadservo-6d488f1be24c1b679931d6d02703f4a10759eb49.tar.gz
servo-6d488f1be24c1b679931d6d02703f4a10759eb49.zip
Auto merge of #24435 - marmeladema:issue-23607/compat, r=jdm
Issue 23607: first pass of changes for compatibility with Python3 As much as i want to migrate entirely to Python3 (see #23607), it will require some time as changes in web-platform-tests are significant and rely on upstream fixes to be merged and synced downstream. In the meantime, lets improve compatibility with Python3 so that later, migration will be less painful. Build system is definitely not ready yet for Python3, but its a step in the right direction. --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `___` with appropriate data: --> - [x ] `./mach build -d` does not report any errors - [ x] `./mach test-tidy` does not report any errors <!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.--> <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->
Diffstat (limited to 'python/servo/util.py')
-rw-r--r--python/servo/util.py18
1 files changed, 9 insertions, 9 deletions
diff --git a/python/servo/util.py b/python/servo/util.py
index 818240d39e6..38127093ae8 100644
--- a/python/servo/util.py
+++ b/python/servo/util.py
@@ -16,11 +16,11 @@ 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
-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,16 +136,16 @@ def download(desc, src, writer, start_byte=0):
if not dumb:
print()
- except urllib2.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 urllib2.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:
@@ -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()