Skip to content

Commit 725f2c3

Browse files
authored
Merge pull request josegonzalez#158 from albertyw/python3
Remove support for python 2
2 parents 41ece08 + cb1b0b6 commit 725f2c3

2 files changed

Lines changed: 16 additions & 51 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__
@@ -366,10 +350,9 @@ def get_auth(args, encode=True, for_git_cli=False):
366350
'-s', args.osx_keychain_item_name,
367351
'-a', args.osx_keychain_item_account,
368352
'-w'], stderr=devnull).strip())
369-
if not PY2:
370-
token = token.decode('utf-8')
353+
token = token.decode('utf-8')
371354
auth = token + ':' + 'x-oauth-basic'
372-
except SubprocessError:
355+
except subprocess.SubprocessError:
373356
log_error('No password item matching the provided name and account could be found in the osx keychain.')
374357
elif args.osx_keychain_item_account:
375358
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):
553536
if not as_app:
554537
request.add_header('Authorization', 'Basic '.encode('ascii') + auth)
555538
else:
556-
if not PY2:
557-
auth = auth.encode('ascii')
539+
auth = auth.encode('ascii')
558540
request.add_header('Authorization', 'token '.encode('ascii') + auth)
559541
request.add_header('Accept', 'application/vnd.github.machine-man-preview+json')
560542
log_info('Requesting {}?{}'.format(template, querystring))
@@ -612,11 +594,7 @@ class S3HTTPRedirectHandler(HTTPRedirectHandler):
612594
so we should remove said header on redirect.
613595
"""
614596
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)
620598
del request.headers['Authorization']
621599
return request
622600

setup.py

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,9 @@
11
#!/usr/bin/env python
22
# -*- coding: utf-8 -*-
33
import os
4-
from github_backup import __version__
5-
6-
try:
7-
from setuptools import setup
8-
setup # workaround for pyflakes issue #13
9-
except ImportError:
10-
from distutils.core import setup
4+
from setuptools import setup
115

12-
# Hack to prevent stupid TypeError: 'NoneType' object is not callable error on
13-
# exit of python setup.py test # in multiprocessing/util.py _exit_function when
14-
# running python setup.py test (see
15-
# http://www.eby-sarna.com/pipermail/peak/2010-May/003357.html)
16-
try:
17-
import multiprocessing
18-
multiprocessing
19-
except ImportError:
20-
pass
6+
from github_backup import __version__
217

228

239
def open_file(fname):
@@ -37,9 +23,10 @@ def open_file(fname):
3723
'Development Status :: 5 - Production/Stable',
3824
'Topic :: System :: Archiving :: Backup',
3925
'License :: OSI Approved :: MIT License',
40-
'Programming Language :: Python :: 2.7',
4126
'Programming Language :: Python :: 3.5',
4227
'Programming Language :: Python :: 3.6',
28+
'Programming Language :: Python :: 3.7',
29+
'Programming Language :: Python :: 3.8',
4330
],
4431
description='backup a github user or organization',
4532
long_description=open_file('README.rst').read(),

0 commit comments

Comments
 (0)