mirror of
https://github.com/josegonzalez/python-github-backup.git
synced 2025-12-05 16:18:02 +01:00
Merge pull request #158 from albertyw/python3
Remove support for python 2
This commit is contained in:
@@ -19,9 +19,6 @@ import subprocess
|
|||||||
import sys
|
import sys
|
||||||
import time
|
import time
|
||||||
import platform
|
import platform
|
||||||
PY2 = False
|
|
||||||
try:
|
|
||||||
# python 3
|
|
||||||
from urllib.parse import urlparse
|
from urllib.parse import urlparse
|
||||||
from urllib.parse import quote as urlquote
|
from urllib.parse import quote as urlquote
|
||||||
from urllib.parse import urlencode
|
from urllib.parse import urlencode
|
||||||
@@ -30,19 +27,6 @@ try:
|
|||||||
from urllib.request import Request
|
from urllib.request import Request
|
||||||
from urllib.request import HTTPRedirectHandler
|
from urllib.request import HTTPRedirectHandler
|
||||||
from urllib.request import build_opener
|
from urllib.request import build_opener
|
||||||
from subprocess import SubprocessError
|
|
||||||
except ImportError:
|
|
||||||
# python 2
|
|
||||||
PY2 = True
|
|
||||||
from subprocess import CalledProcessError as SubprocessError
|
|
||||||
from urlparse import urlparse
|
|
||||||
from urllib import quote as urlquote
|
|
||||||
from urllib import urlencode
|
|
||||||
from urllib2 import HTTPError, URLError
|
|
||||||
from urllib2 import urlopen
|
|
||||||
from urllib2 import Request
|
|
||||||
from urllib2 import HTTPRedirectHandler
|
|
||||||
from urllib2 import build_opener
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from . import __version__
|
from . import __version__
|
||||||
@@ -366,10 +350,9 @@ def get_auth(args, encode=True, for_git_cli=False):
|
|||||||
'-s', args.osx_keychain_item_name,
|
'-s', args.osx_keychain_item_name,
|
||||||
'-a', args.osx_keychain_item_account,
|
'-a', args.osx_keychain_item_account,
|
||||||
'-w'], stderr=devnull).strip())
|
'-w'], stderr=devnull).strip())
|
||||||
if not PY2:
|
|
||||||
token = token.decode('utf-8')
|
token = token.decode('utf-8')
|
||||||
auth = token + ':' + 'x-oauth-basic'
|
auth = token + ':' + 'x-oauth-basic'
|
||||||
except SubprocessError:
|
except subprocess.SubprocessError:
|
||||||
log_error('No password item matching the provided name and account could be found in the osx keychain.')
|
log_error('No password item matching the provided name and account could be found in the osx keychain.')
|
||||||
elif args.osx_keychain_item_account:
|
elif args.osx_keychain_item_account:
|
||||||
log_error('You must specify both name and account fields for osx keychain password items')
|
log_error('You must specify both name and account fields for osx keychain password items')
|
||||||
@@ -553,7 +536,6 @@ def _construct_request(per_page, page, query_args, template, auth, as_app=None):
|
|||||||
if not as_app:
|
if not as_app:
|
||||||
request.add_header('Authorization', 'Basic '.encode('ascii') + auth)
|
request.add_header('Authorization', 'Basic '.encode('ascii') + auth)
|
||||||
else:
|
else:
|
||||||
if not PY2:
|
|
||||||
auth = auth.encode('ascii')
|
auth = auth.encode('ascii')
|
||||||
request.add_header('Authorization', 'token '.encode('ascii') + auth)
|
request.add_header('Authorization', 'token '.encode('ascii') + auth)
|
||||||
request.add_header('Accept', 'application/vnd.github.machine-man-preview+json')
|
request.add_header('Accept', 'application/vnd.github.machine-man-preview+json')
|
||||||
@@ -612,10 +594,6 @@ class S3HTTPRedirectHandler(HTTPRedirectHandler):
|
|||||||
so we should remove said header on redirect.
|
so we should remove said header on redirect.
|
||||||
"""
|
"""
|
||||||
def redirect_request(self, req, fp, code, msg, headers, newurl):
|
def redirect_request(self, req, fp, code, msg, headers, newurl):
|
||||||
if PY2:
|
|
||||||
# HTTPRedirectHandler is an old style class
|
|
||||||
request = HTTPRedirectHandler.redirect_request(self, req, fp, code, msg, headers, newurl)
|
|
||||||
else:
|
|
||||||
request = super(S3HTTPRedirectHandler, self).redirect_request(req, fp, code, msg, headers, newurl)
|
request = super(S3HTTPRedirectHandler, self).redirect_request(req, fp, code, msg, headers, newurl)
|
||||||
del request.headers['Authorization']
|
del request.headers['Authorization']
|
||||||
return request
|
return request
|
||||||
|
|||||||
19
setup.py
19
setup.py
@@ -1,23 +1,9 @@
|
|||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
import os
|
import os
|
||||||
from github_backup import __version__
|
|
||||||
|
|
||||||
try:
|
|
||||||
from setuptools import setup
|
from setuptools import setup
|
||||||
setup # workaround for pyflakes issue #13
|
|
||||||
except ImportError:
|
|
||||||
from distutils.core import setup
|
|
||||||
|
|
||||||
# Hack to prevent stupid TypeError: 'NoneType' object is not callable error on
|
from github_backup import __version__
|
||||||
# exit of python setup.py test # in multiprocessing/util.py _exit_function when
|
|
||||||
# running python setup.py test (see
|
|
||||||
# http://www.eby-sarna.com/pipermail/peak/2010-May/003357.html)
|
|
||||||
try:
|
|
||||||
import multiprocessing
|
|
||||||
multiprocessing
|
|
||||||
except ImportError:
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
def open_file(fname):
|
def open_file(fname):
|
||||||
@@ -37,9 +23,10 @@ setup(
|
|||||||
'Development Status :: 5 - Production/Stable',
|
'Development Status :: 5 - Production/Stable',
|
||||||
'Topic :: System :: Archiving :: Backup',
|
'Topic :: System :: Archiving :: Backup',
|
||||||
'License :: OSI Approved :: MIT License',
|
'License :: OSI Approved :: MIT License',
|
||||||
'Programming Language :: Python :: 2.7',
|
|
||||||
'Programming Language :: Python :: 3.5',
|
'Programming Language :: Python :: 3.5',
|
||||||
'Programming Language :: Python :: 3.6',
|
'Programming Language :: Python :: 3.6',
|
||||||
|
'Programming Language :: Python :: 3.7',
|
||||||
|
'Programming Language :: Python :: 3.8',
|
||||||
],
|
],
|
||||||
description='backup a github user or organization',
|
description='backup a github user or organization',
|
||||||
long_description=open_file('README.rst').read(),
|
long_description=open_file('README.rst').read(),
|
||||||
|
|||||||
Reference in New Issue
Block a user