Skip to content

Commit d7b8526

Browse files
committed
Remove python 2 specific logic
1 parent 031a984 commit d7b8526

1 file changed

Lines changed: 12 additions & 34 deletions

File tree

github_backup/github_backup.py

Lines changed: 12 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -19,30 +19,14 @@
1919
import sys
2020
import time
2121
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
4630

4731
try:
4832
from . import __version__
@@ -362,10 +346,9 @@ def get_auth(args, encode=True, for_git_cli=False):
362346
'-s', args.osx_keychain_item_name,
363347
'-a', args.osx_keychain_item_account,
364348
'-w'], stderr=devnull).strip())
365-
if not PY2:
366-
token = token.decode('utf-8')
349+
token = token.decode('utf-8')
367350
auth = token + ':' + 'x-oauth-basic'
368-
except SubprocessError:
351+
except subprocess.SubprocessError:
369352
log_error('No password item matching the provided name and account could be found in the osx keychain.')
370353
elif args.osx_keychain_item_account:
371354
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):
549532
if not as_app:
550533
request.add_header('Authorization', 'Basic '.encode('ascii') + auth)
551534
else:
552-
if not PY2:
553-
auth = auth.encode('ascii')
535+
auth = auth.encode('ascii')
554536
request.add_header('Authorization', 'token '.encode('ascii') + auth)
555537
request.add_header('Accept', 'application/vnd.github.machine-man-preview+json')
556538
log_info('Requesting {}?{}'.format(template, querystring))
@@ -608,11 +590,7 @@ class S3HTTPRedirectHandler(HTTPRedirectHandler):
608590
so we should remove said header on redirect.
609591
"""
610592
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)
616594
del request.headers['Authorization']
617595
return request
618596

0 commit comments

Comments
 (0)