|
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__ |
@@ -366,10 +350,9 @@ def get_auth(args, encode=True, for_git_cli=False): |
366 | 350 | '-s', args.osx_keychain_item_name, |
367 | 351 | '-a', args.osx_keychain_item_account, |
368 | 352 | '-w'], stderr=devnull).strip()) |
369 | | - if not PY2: |
370 | | - token = token.decode('utf-8') |
| 353 | + token = token.decode('utf-8') |
371 | 354 | auth = token + ':' + 'x-oauth-basic' |
372 | | - except SubprocessError: |
| 355 | + except subprocess.SubprocessError: |
373 | 356 | log_error('No password item matching the provided name and account could be found in the osx keychain.') |
374 | 357 | elif args.osx_keychain_item_account: |
375 | 358 | log_error('You must specify both name and account fields for osx keychain password items') |
@@ -553,8 +536,7 @@ def _construct_request(per_page, page, query_args, template, auth, as_app=None): |
553 | 536 | if not as_app: |
554 | 537 | request.add_header('Authorization', 'Basic '.encode('ascii') + auth) |
555 | 538 | else: |
556 | | - if not PY2: |
557 | | - auth = auth.encode('ascii') |
| 539 | + auth = auth.encode('ascii') |
558 | 540 | request.add_header('Authorization', 'token '.encode('ascii') + auth) |
559 | 541 | request.add_header('Accept', 'application/vnd.github.machine-man-preview+json') |
560 | 542 | log_info('Requesting {}?{}'.format(template, querystring)) |
@@ -612,11 +594,7 @@ class S3HTTPRedirectHandler(HTTPRedirectHandler): |
612 | 594 | so we should remove said header on redirect. |
613 | 595 | """ |
614 | 596 | def redirect_request(self, req, fp, code, msg, headers, newurl): |
615 | | - if PY2: |
616 | | - # HTTPRedirectHandler is an old style class |
617 | | - request = HTTPRedirectHandler.redirect_request(self, req, fp, code, msg, headers, newurl) |
618 | | - else: |
619 | | - request = super(S3HTTPRedirectHandler, self).redirect_request(req, fp, code, msg, headers, newurl) |
| 597 | + request = super(S3HTTPRedirectHandler, self).redirect_request(req, fp, code, msg, headers, newurl) |
620 | 598 | del request.headers['Authorization'] |
621 | 599 | return request |
622 | 600 |
|
|
0 commit comments