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