From 1f7627fd3ccab0fbab88ad2d082b67f5719af92c Mon Sep 17 00:00:00 2001 From: Sarah Owens Date: Wed, 31 Oct 2012 09:21:55 -0700 Subject: Use python3 urllib when urllib2 not available This is part of a series of changes to introduce Python3 support. Change-Id: I605b145791053c1f2d7bf3c907c5a68649b21d12 --- git_config.py | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) (limited to 'git_config.py') 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: except ImportError: import dummy_threading as _threading import time -import urllib2 +try: + import urllib2 +except ImportError: + # For python3 + import urllib.request + import urllib.error +else: + # For python2 + import imp + urllib = imp.new_module('urllib') + urllib.request = urllib2 + urllib.error = urllib2 from signal import SIGTERM from error import GitError, UploadError @@ -580,7 +591,7 @@ class Remote(object): else: try: info_url = u + 'ssh_info' - info = urllib2.urlopen(info_url).read() + info = urllib.request.urlopen(info_url).read() if '<' in info: # Assume the server gave us some sort of HTML # response back, like maybe a login page. @@ -593,9 +604,9 @@ class Remote(object): else: host, port = info.split() self._review_url = self._SshReviewUrl(userEmail, host, port) - except urllib2.HTTPError as e: + except urllib.error.HTTPError as e: raise UploadError('%s: %s' % (self.review, str(e))) - except urllib2.URLError as e: + except urllib.error.URLError as e: raise UploadError('%s: %s' % (self.review, str(e))) REVIEW_CACHE[u] = self._review_url -- cgit v1.2.3-54-g00ecf