diff options
Diffstat (limited to 'repo')
-rwxr-xr-x | repo | 33 |
1 files changed, 22 insertions, 11 deletions
@@ -122,7 +122,18 @@ import os | |||
122 | import re | 122 | import re |
123 | import subprocess | 123 | import subprocess |
124 | import sys | 124 | import sys |
125 | import urllib2 | 125 | try: |
126 | import urllib2 | ||
127 | except ImportError: | ||
128 | # For python3 | ||
129 | import urllib.request | ||
130 | import urllib.error | ||
131 | else: | ||
132 | # For python2 | ||
133 | import imp | ||
134 | urllib = imp.new_module('urllib') | ||
135 | urllib.request = urllib2 | ||
136 | urllib.error = urllib2 | ||
126 | 137 | ||
127 | home_dot_repo = os.path.expanduser('~/.repoconfig') | 138 | home_dot_repo = os.path.expanduser('~/.repoconfig') |
128 | gpg_dir = os.path.join(home_dot_repo, 'gnupg') | 139 | gpg_dir = os.path.join(home_dot_repo, 'gnupg') |
@@ -355,7 +366,7 @@ def _SetConfig(local, name, value): | |||
355 | def _InitHttp(): | 366 | def _InitHttp(): |
356 | handlers = [] | 367 | handlers = [] |
357 | 368 | ||
358 | mgr = urllib2.HTTPPasswordMgrWithDefaultRealm() | 369 | mgr = urllib.request.HTTPPasswordMgrWithDefaultRealm() |
359 | try: | 370 | try: |
360 | import netrc | 371 | import netrc |
361 | n = netrc.netrc() | 372 | n = netrc.netrc() |
@@ -365,16 +376,16 @@ def _InitHttp(): | |||
365 | mgr.add_password(p[1], 'https://%s/' % host, p[0], p[2]) | 376 | mgr.add_password(p[1], 'https://%s/' % host, p[0], p[2]) |
366 | except: | 377 | except: |
367 | pass | 378 | pass |
368 | handlers.append(urllib2.HTTPBasicAuthHandler(mgr)) | 379 | handlers.append(urllib.request.HTTPBasicAuthHandler(mgr)) |
369 | handlers.append(urllib2.HTTPDigestAuthHandler(mgr)) | 380 | handlers.append(urllib.request.HTTPDigestAuthHandler(mgr)) |
370 | 381 | ||
371 | if 'http_proxy' in os.environ: | 382 | if 'http_proxy' in os.environ: |
372 | url = os.environ['http_proxy'] | 383 | url = os.environ['http_proxy'] |
373 | handlers.append(urllib2.ProxyHandler({'http': url, 'https': url})) | 384 | handlers.append(urllib.request.ProxyHandler({'http': url, 'https': url})) |
374 | if 'REPO_CURL_VERBOSE' in os.environ: | 385 | if 'REPO_CURL_VERBOSE' in os.environ: |
375 | handlers.append(urllib2.HTTPHandler(debuglevel=1)) | 386 | handlers.append(urllib.request.HTTPHandler(debuglevel=1)) |
376 | handlers.append(urllib2.HTTPSHandler(debuglevel=1)) | 387 | handlers.append(urllib.request.HTTPSHandler(debuglevel=1)) |
377 | urllib2.install_opener(urllib2.build_opener(*handlers)) | 388 | urllib.request.install_opener(urllib.request.build_opener(*handlers)) |
378 | 389 | ||
379 | def _Fetch(url, local, src, quiet): | 390 | def _Fetch(url, local, src, quiet): |
380 | if not quiet: | 391 | if not quiet: |
@@ -423,14 +434,14 @@ def _DownloadBundle(url, local, quiet): | |||
423 | dest = open(os.path.join(local, '.git', 'clone.bundle'), 'w+b') | 434 | dest = open(os.path.join(local, '.git', 'clone.bundle'), 'w+b') |
424 | try: | 435 | try: |
425 | try: | 436 | try: |
426 | r = urllib2.urlopen(url) | 437 | r = urllib.request.urlopen(url) |
427 | except urllib2.HTTPError as e: | 438 | except urllib.error.HTTPError as e: |
428 | if e.code == 404: | 439 | if e.code == 404: |
429 | return False | 440 | return False |
430 | print >>sys.stderr, 'fatal: Cannot get %s' % url | 441 | print >>sys.stderr, 'fatal: Cannot get %s' % url |
431 | print >>sys.stderr, 'fatal: HTTP error %s' % e.code | 442 | print >>sys.stderr, 'fatal: HTTP error %s' % e.code |
432 | raise CloneFailure() | 443 | raise CloneFailure() |
433 | except urllib2.URLError as e: | 444 | except urllib.error.URLError as e: |
434 | print >>sys.stderr, 'fatal: Cannot get %s' % url | 445 | print >>sys.stderr, 'fatal: Cannot get %s' % url |
435 | print >>sys.stderr, 'fatal: error %s' % e.reason | 446 | print >>sys.stderr, 'fatal: error %s' % e.reason |
436 | raise CloneFailure() | 447 | raise CloneFailure() |