diff options
author | Sarah Owens <sarato@inkylabs.com> | 2012-10-31 09:21:55 -0700 |
---|---|---|
committer | Sarah Owens <sarato@inkylabs.com> | 2012-10-31 14:26:48 -0700 |
commit | 1f7627fd3ccab0fbab88ad2d082b67f5719af92c (patch) | |
tree | 3c03eb8efbdc001472f09fa31cf11bf1d2ec01c5 /git_config.py | |
parent | 1d947b30342163b723c96db563967323535fef45 (diff) | |
download | git-repo-1f7627fd3ccab0fbab88ad2d082b67f5719af92c.tar.gz |
Use python3 urllib when urllib2 not available
This is part of a series of changes to introduce Python3 support.
Change-Id: I605b145791053c1f2d7bf3c907c5a68649b21d12
Diffstat (limited to 'git_config.py')
-rw-r--r-- | git_config.py | 19 |
1 files changed, 15 insertions, 4 deletions
diff --git a/git_config.py b/git_config.py index d6510aae..6589b193 100644 --- a/git_config.py +++ b/git_config.py | |||
@@ -23,7 +23,18 @@ try: | |||
23 | except ImportError: | 23 | except ImportError: |
24 | import dummy_threading as _threading | 24 | import dummy_threading as _threading |
25 | import time | 25 | import time |
26 | import urllib2 | 26 | try: |
27 | import urllib2 | ||
28 | except ImportError: | ||
29 | # For python3 | ||
30 | import urllib.request | ||
31 | import urllib.error | ||
32 | else: | ||
33 | # For python2 | ||
34 | import imp | ||
35 | urllib = imp.new_module('urllib') | ||
36 | urllib.request = urllib2 | ||
37 | urllib.error = urllib2 | ||
27 | 38 | ||
28 | from signal import SIGTERM | 39 | from signal import SIGTERM |
29 | from error import GitError, UploadError | 40 | from error import GitError, UploadError |
@@ -580,7 +591,7 @@ class Remote(object): | |||
580 | else: | 591 | else: |
581 | try: | 592 | try: |
582 | info_url = u + 'ssh_info' | 593 | info_url = u + 'ssh_info' |
583 | info = urllib2.urlopen(info_url).read() | 594 | info = urllib.request.urlopen(info_url).read() |
584 | if '<' in info: | 595 | if '<' in info: |
585 | # Assume the server gave us some sort of HTML | 596 | # Assume the server gave us some sort of HTML |
586 | # response back, like maybe a login page. | 597 | # response back, like maybe a login page. |
@@ -593,9 +604,9 @@ class Remote(object): | |||
593 | else: | 604 | else: |
594 | host, port = info.split() | 605 | host, port = info.split() |
595 | self._review_url = self._SshReviewUrl(userEmail, host, port) | 606 | self._review_url = self._SshReviewUrl(userEmail, host, port) |
596 | except urllib2.HTTPError as e: | 607 | except urllib.error.HTTPError as e: |
597 | raise UploadError('%s: %s' % (self.review, str(e))) | 608 | raise UploadError('%s: %s' % (self.review, str(e))) |
598 | except urllib2.URLError as e: | 609 | except urllib.error.URLError as e: |
599 | raise UploadError('%s: %s' % (self.review, str(e))) | 610 | raise UploadError('%s: %s' % (self.review, str(e))) |
600 | 611 | ||
601 | REVIEW_CACHE[u] = self._review_url | 612 | REVIEW_CACHE[u] = self._review_url |