diff options
Diffstat (limited to 'main.py')
-rwxr-xr-x | main.py | 35 |
1 files changed, 22 insertions, 13 deletions
@@ -29,7 +29,16 @@ import optparse | |||
29 | import os | 29 | import os |
30 | import sys | 30 | import sys |
31 | import time | 31 | import time |
32 | import urllib2 | 32 | try: |
33 | import urllib2 | ||
34 | except ImportError: | ||
35 | # For python3 | ||
36 | import urllib.request | ||
37 | else: | ||
38 | # For python2 | ||
39 | import imp | ||
40 | urllib = imp.new_module('urllib') | ||
41 | urllib.request = urllib2 | ||
33 | 42 | ||
34 | from trace import SetTrace | 43 | from trace import SetTrace |
35 | from git_command import git, GitCommand | 44 | from git_command import git, GitCommand |
@@ -267,7 +276,7 @@ def _UserAgent(): | |||
267 | py_version[0], py_version[1], py_version[2]) | 276 | py_version[0], py_version[1], py_version[2]) |
268 | return _user_agent | 277 | return _user_agent |
269 | 278 | ||
270 | class _UserAgentHandler(urllib2.BaseHandler): | 279 | class _UserAgentHandler(urllib.request.BaseHandler): |
271 | def http_request(self, req): | 280 | def http_request(self, req): |
272 | req.add_header('User-Agent', _UserAgent()) | 281 | req.add_header('User-Agent', _UserAgent()) |
273 | return req | 282 | return req |
@@ -289,10 +298,10 @@ def _AddPasswordFromUserInput(handler, msg, req): | |||
289 | return | 298 | return |
290 | handler.passwd.add_password(None, url, user, password) | 299 | handler.passwd.add_password(None, url, user, password) |
291 | 300 | ||
292 | class _BasicAuthHandler(urllib2.HTTPBasicAuthHandler): | 301 | class _BasicAuthHandler(urllib.request.HTTPBasicAuthHandler): |
293 | def http_error_401(self, req, fp, code, msg, headers): | 302 | def http_error_401(self, req, fp, code, msg, headers): |
294 | _AddPasswordFromUserInput(self, msg, req) | 303 | _AddPasswordFromUserInput(self, msg, req) |
295 | return urllib2.HTTPBasicAuthHandler.http_error_401( | 304 | return urllib.request.HTTPBasicAuthHandler.http_error_401( |
296 | self, req, fp, code, msg, headers) | 305 | self, req, fp, code, msg, headers) |
297 | 306 | ||
298 | def http_error_auth_reqed(self, authreq, host, req, headers): | 307 | def http_error_auth_reqed(self, authreq, host, req, headers): |
@@ -302,7 +311,7 @@ class _BasicAuthHandler(urllib2.HTTPBasicAuthHandler): | |||
302 | val = val.replace('\n', '') | 311 | val = val.replace('\n', '') |
303 | old_add_header(name, val) | 312 | old_add_header(name, val) |
304 | req.add_header = _add_header | 313 | req.add_header = _add_header |
305 | return urllib2.AbstractBasicAuthHandler.http_error_auth_reqed( | 314 | return urllib.request.AbstractBasicAuthHandler.http_error_auth_reqed( |
306 | self, authreq, host, req, headers) | 315 | self, authreq, host, req, headers) |
307 | except: | 316 | except: |
308 | reset = getattr(self, 'reset_retry_count', None) | 317 | reset = getattr(self, 'reset_retry_count', None) |
@@ -312,10 +321,10 @@ class _BasicAuthHandler(urllib2.HTTPBasicAuthHandler): | |||
312 | self.retried = 0 | 321 | self.retried = 0 |
313 | raise | 322 | raise |
314 | 323 | ||
315 | class _DigestAuthHandler(urllib2.HTTPDigestAuthHandler): | 324 | class _DigestAuthHandler(urllib.request.HTTPDigestAuthHandler): |
316 | def http_error_401(self, req, fp, code, msg, headers): | 325 | def http_error_401(self, req, fp, code, msg, headers): |
317 | _AddPasswordFromUserInput(self, msg, req) | 326 | _AddPasswordFromUserInput(self, msg, req) |
318 | return urllib2.HTTPDigestAuthHandler.http_error_401( | 327 | return urllib.request.HTTPDigestAuthHandler.http_error_401( |
319 | self, req, fp, code, msg, headers) | 328 | self, req, fp, code, msg, headers) |
320 | 329 | ||
321 | def http_error_auth_reqed(self, auth_header, host, req, headers): | 330 | def http_error_auth_reqed(self, auth_header, host, req, headers): |
@@ -325,7 +334,7 @@ class _DigestAuthHandler(urllib2.HTTPDigestAuthHandler): | |||
325 | val = val.replace('\n', '') | 334 | val = val.replace('\n', '') |
326 | old_add_header(name, val) | 335 | old_add_header(name, val) |
327 | req.add_header = _add_header | 336 | req.add_header = _add_header |
328 | return urllib2.AbstractDigestAuthHandler.http_error_auth_reqed( | 337 | return urllib.request.AbstractDigestAuthHandler.http_error_auth_reqed( |
329 | self, auth_header, host, req, headers) | 338 | self, auth_header, host, req, headers) |
330 | except: | 339 | except: |
331 | reset = getattr(self, 'reset_retry_count', None) | 340 | reset = getattr(self, 'reset_retry_count', None) |
@@ -338,7 +347,7 @@ class _DigestAuthHandler(urllib2.HTTPDigestAuthHandler): | |||
338 | def init_http(): | 347 | def init_http(): |
339 | handlers = [_UserAgentHandler()] | 348 | handlers = [_UserAgentHandler()] |
340 | 349 | ||
341 | mgr = urllib2.HTTPPasswordMgrWithDefaultRealm() | 350 | mgr = urllib.request.HTTPPasswordMgrWithDefaultRealm() |
342 | try: | 351 | try: |
343 | n = netrc.netrc() | 352 | n = netrc.netrc() |
344 | for host in n.hosts: | 353 | for host in n.hosts: |
@@ -354,11 +363,11 @@ def init_http(): | |||
354 | 363 | ||
355 | if 'http_proxy' in os.environ: | 364 | if 'http_proxy' in os.environ: |
356 | url = os.environ['http_proxy'] | 365 | url = os.environ['http_proxy'] |
357 | handlers.append(urllib2.ProxyHandler({'http': url, 'https': url})) | 366 | handlers.append(urllib.request.ProxyHandler({'http': url, 'https': url})) |
358 | if 'REPO_CURL_VERBOSE' in os.environ: | 367 | if 'REPO_CURL_VERBOSE' in os.environ: |
359 | handlers.append(urllib2.HTTPHandler(debuglevel=1)) | 368 | handlers.append(urllib.request.HTTPHandler(debuglevel=1)) |
360 | handlers.append(urllib2.HTTPSHandler(debuglevel=1)) | 369 | handlers.append(urllib.request.HTTPSHandler(debuglevel=1)) |
361 | urllib2.install_opener(urllib2.build_opener(*handlers)) | 370 | urllib.request.install_opener(urllib.request.build_opener(*handlers)) |
362 | 371 | ||
363 | def _Main(argv): | 372 | def _Main(argv): |
364 | result = 0 | 373 | result = 0 |