mirror of
https://gerrit.googlesource.com/git-repo
synced 2025-01-02 16:14:25 +00:00
handle binary stream from urllib.request.urlopen
Python 3 returns bytes by default with urlopen. Adjust our code to handle that scenario and decode as necessary. Bug: https://crbug.com/gerrit/10418 Change-Id: Icf4cd80e7ef92d71a3eefbc6113f1ba11c32eebc
This commit is contained in:
parent
3698ab7c92
commit
1b9adab75a
@ -657,13 +657,14 @@ class Remote(object):
|
|||||||
info = urllib.request.urlopen(info_url, context=context).read()
|
info = urllib.request.urlopen(info_url, context=context).read()
|
||||||
else:
|
else:
|
||||||
info = urllib.request.urlopen(info_url).read()
|
info = urllib.request.urlopen(info_url).read()
|
||||||
if info == 'NOT_AVAILABLE' or '<' in info:
|
if info == b'NOT_AVAILABLE' or b'<' in info:
|
||||||
# If `info` contains '<', we assume the server gave us some sort
|
# If `info` contains '<', we assume the server gave us some sort
|
||||||
# of HTML response back, like maybe a login page.
|
# of HTML response back, like maybe a login page.
|
||||||
#
|
#
|
||||||
# Assume HTTP if SSH is not enabled or ssh_info doesn't look right.
|
# Assume HTTP if SSH is not enabled or ssh_info doesn't look right.
|
||||||
self._review_url = http_url
|
self._review_url = http_url
|
||||||
else:
|
else:
|
||||||
|
info = info.decode('utf-8')
|
||||||
host, port = info.split()
|
host, port = info.split()
|
||||||
self._review_url = self._SshReviewUrl(userEmail, host, port)
|
self._review_url = self._SshReviewUrl(userEmail, host, port)
|
||||||
except urllib.error.HTTPError as e:
|
except urllib.error.HTTPError as e:
|
||||||
|
2
repo
2
repo
@ -583,7 +583,7 @@ def _DownloadBundle(url, local, quiet):
|
|||||||
print('Get %s' % url, file=sys.stderr)
|
print('Get %s' % url, file=sys.stderr)
|
||||||
while True:
|
while True:
|
||||||
buf = r.read(8192)
|
buf = r.read(8192)
|
||||||
if buf == '':
|
if not buf:
|
||||||
return True
|
return True
|
||||||
dest.write(buf)
|
dest.write(buf)
|
||||||
finally:
|
finally:
|
||||||
|
Loading…
Reference in New Issue
Block a user