summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMike Frysinger <vapier@google.com>2019-07-04 17:54:54 -0400
committerMike Frysinger <vapier@google.com>2019-07-04 18:19:00 -0400
commit1b9adab75a87c5eb94c3c3b653fdc2c123ba0077 (patch)
tree32fe34adf853573fb11749f09b60c8a0f7b93399
parent3698ab7c9200a2b65652e9a5f3a763cd7629af0c (diff)
downloadgit-repo-1b9adab75a87c5eb94c3c3b653fdc2c123ba0077.tar.gz
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
-rw-r--r--git_config.py3
-rwxr-xr-xrepo2
2 files changed, 3 insertions, 2 deletions
diff --git a/git_config.py b/git_config.py
index ca1282a3..cdfeddd0 100644
--- a/git_config.py
+++ b/git_config.py
@@ -657,13 +657,14 @@ class Remote(object):
657 info = urllib.request.urlopen(info_url, context=context).read() 657 info = urllib.request.urlopen(info_url, context=context).read()
658 else: 658 else:
659 info = urllib.request.urlopen(info_url).read() 659 info = urllib.request.urlopen(info_url).read()
660 if info == 'NOT_AVAILABLE' or '<' in info: 660 if info == b'NOT_AVAILABLE' or b'<' in info:
661 # If `info` contains '<', we assume the server gave us some sort 661 # If `info` contains '<', we assume the server gave us some sort
662 # of HTML response back, like maybe a login page. 662 # of HTML response back, like maybe a login page.
663 # 663 #
664 # Assume HTTP if SSH is not enabled or ssh_info doesn't look right. 664 # Assume HTTP if SSH is not enabled or ssh_info doesn't look right.
665 self._review_url = http_url 665 self._review_url = http_url
666 else: 666 else:
667 info = info.decode('utf-8')
667 host, port = info.split() 668 host, port = info.split()
668 self._review_url = self._SshReviewUrl(userEmail, host, port) 669 self._review_url = self._SshReviewUrl(userEmail, host, port)
669 except urllib.error.HTTPError as e: 670 except urllib.error.HTTPError as e:
diff --git a/repo b/repo
index aa357a22..ce42ad06 100755
--- a/repo
+++ b/repo
@@ -583,7 +583,7 @@ def _DownloadBundle(url, local, quiet):
583 print('Get %s' % url, file=sys.stderr) 583 print('Get %s' % url, file=sys.stderr)
584 while True: 584 while True:
585 buf = r.read(8192) 585 buf = r.read(8192)
586 if buf == '': 586 if not buf:
587 return True 587 return True
588 dest.write(buf) 588 dest.write(buf)
589 finally: 589 finally: