|
19 | 19 | import sys |
20 | 20 | import time |
21 | 21 | import platform |
22 | | -PY2 = False |
23 | | -try: |
24 | | - # python 3 |
25 | | - from urllib.parse import urlparse |
26 | | - from urllib.parse import quote as urlquote |
27 | | - from urllib.parse import urlencode |
28 | | - from urllib.error import HTTPError, URLError |
29 | | - from urllib.request import urlopen |
30 | | - from urllib.request import Request |
31 | | - from urllib.request import HTTPRedirectHandler |
32 | | - from urllib.request import build_opener |
33 | | - from subprocess import SubprocessError |
34 | | -except ImportError: |
35 | | - # python 2 |
36 | | - PY2 = True |
37 | | - from subprocess import CalledProcessError as SubprocessError |
38 | | - from urlparse import urlparse |
39 | | - from urllib import quote as urlquote |
40 | | - from urllib import urlencode |
41 | | - from urllib2 import HTTPError, URLError |
42 | | - from urllib2 import urlopen |
43 | | - from urllib2 import Request |
44 | | - from urllib2 import HTTPRedirectHandler |
45 | | - from urllib2 import build_opener |
| 22 | +from urllib.parse import urlparse |
| 23 | +from urllib.parse import quote as urlquote |
| 24 | +from urllib.parse import urlencode |
| 25 | +from urllib.error import HTTPError, URLError |
| 26 | +from urllib.request import urlopen |
| 27 | +from urllib.request import Request |
| 28 | +from urllib.request import HTTPRedirectHandler |
| 29 | +from urllib.request import build_opener |
46 | 30 |
|
47 | 31 | try: |
48 | 32 | from . import __version__ |
@@ -362,10 +346,9 @@ def get_auth(args, encode=True, for_git_cli=False): |
362 | 346 | '-s', args.osx_keychain_item_name, |
363 | 347 | '-a', args.osx_keychain_item_account, |
364 | 348 | '-w'], stderr=devnull).strip()) |
365 | | - if not PY2: |
366 | | - token = token.decode('utf-8') |
| 349 | + token = token.decode('utf-8') |
367 | 350 | auth = token + ':' + 'x-oauth-basic' |
368 | | - except SubprocessError: |
| 351 | + except subprocess.SubprocessError: |
369 | 352 | log_error('No password item matching the provided name and account could be found in the osx keychain.') |
370 | 353 | elif args.osx_keychain_item_account: |
371 | 354 | log_error('You must specify both name and account fields for osx keychain password items') |
@@ -549,8 +532,7 @@ def _construct_request(per_page, page, query_args, template, auth, as_app=None): |
549 | 532 | if not as_app: |
550 | 533 | request.add_header('Authorization', 'Basic '.encode('ascii') + auth) |
551 | 534 | else: |
552 | | - if not PY2: |
553 | | - auth = auth.encode('ascii') |
| 535 | + auth = auth.encode('ascii') |
554 | 536 | request.add_header('Authorization', 'token '.encode('ascii') + auth) |
555 | 537 | request.add_header('Accept', 'application/vnd.github.machine-man-preview+json') |
556 | 538 | log_info('Requesting {}?{}'.format(template, querystring)) |
@@ -608,11 +590,7 @@ class S3HTTPRedirectHandler(HTTPRedirectHandler): |
608 | 590 | so we should remove said header on redirect. |
609 | 591 | """ |
610 | 592 | def redirect_request(self, req, fp, code, msg, headers, newurl): |
611 | | - if PY2: |
612 | | - # HTTPRedirectHandler is an old style class |
613 | | - request = HTTPRedirectHandler.redirect_request(self, req, fp, code, msg, headers, newurl) |
614 | | - else: |
615 | | - request = super(S3HTTPRedirectHandler, self).redirect_request(req, fp, code, msg, headers, newurl) |
| 593 | + request = super(S3HTTPRedirectHandler, self).redirect_request(req, fp, code, msg, headers, newurl) |
616 | 594 | del request.headers['Authorization'] |
617 | 595 | return request |
618 | 596 |
|
|
0 commit comments