mirror of
https://github.com/status-im/PyGithub.git
synced 2026-08-31 19:01:15 +00:00
Switch to using six (#1189)
With the Python 2.7 deadline fast approaching, modernize the codebase making use of the modernize module to switch to using six, as well as other upcoming features, such as absolute imports . Stop using 2to3 for Travis, yay!
This commit is contained in:
+44
-42
@@ -48,6 +48,7 @@
|
||||
# #
|
||||
################################################################################
|
||||
|
||||
from __future__ import absolute_import
|
||||
import datetime
|
||||
|
||||
import pickle
|
||||
@@ -57,24 +58,25 @@ import requests
|
||||
import jwt
|
||||
import urllib3
|
||||
|
||||
from Requester import Requester
|
||||
import AuthenticatedUser
|
||||
import NamedUser
|
||||
import Gist
|
||||
from .Requester import Requester
|
||||
from . import AuthenticatedUser
|
||||
from . import NamedUser
|
||||
from . import Gist
|
||||
import github.PaginatedList
|
||||
import Repository
|
||||
import Installation
|
||||
import License
|
||||
import Topic
|
||||
from . import Repository
|
||||
from . import Installation
|
||||
from . import License
|
||||
from . import Topic
|
||||
import github.GithubObject
|
||||
import HookDescription
|
||||
import GitignoreTemplate
|
||||
import RateLimit
|
||||
import InstallationAuthorization
|
||||
import GithubException
|
||||
import Invitation
|
||||
from . import HookDescription
|
||||
from . import GitignoreTemplate
|
||||
from . import RateLimit
|
||||
from . import InstallationAuthorization
|
||||
from . import GithubException
|
||||
from . import Invitation
|
||||
|
||||
import Consts
|
||||
from . import Consts
|
||||
import six
|
||||
|
||||
atLeastPython3 = sys.hexversion >= 0x03000000
|
||||
|
||||
@@ -106,14 +108,14 @@ class Github(object):
|
||||
:param retry: int or urllib3.util.retry.Retry object
|
||||
"""
|
||||
|
||||
assert login_or_token is None or isinstance(login_or_token, (str, unicode)), login_or_token
|
||||
assert password is None or isinstance(password, (str, unicode)), password
|
||||
assert jwt is None or isinstance(jwt, (str, unicode)), jwt
|
||||
assert isinstance(base_url, (str, unicode)), base_url
|
||||
assert isinstance(timeout, (int, long)), timeout
|
||||
assert client_id is None or isinstance(client_id, (str, unicode)), client_id
|
||||
assert client_secret is None or isinstance(client_secret, (str, unicode)), client_secret
|
||||
assert user_agent is None or isinstance(user_agent, (str, unicode)), user_agent
|
||||
assert login_or_token is None or isinstance(login_or_token, (str, six.text_type)), login_or_token
|
||||
assert password is None or isinstance(password, (str, six.text_type)), password
|
||||
assert jwt is None or isinstance(jwt, (str, six.text_type)), jwt
|
||||
assert isinstance(base_url, (str, six.text_type)), base_url
|
||||
assert isinstance(timeout, six.integer_types), timeout
|
||||
assert client_id is None or isinstance(client_id, (str, six.text_type)), client_id
|
||||
assert client_secret is None or isinstance(client_secret, (str, six.text_type)), client_secret
|
||||
assert user_agent is None or isinstance(user_agent, (str, six.text_type)), user_agent
|
||||
assert isinstance(api_preview, (bool))
|
||||
assert retry is None or isinstance(retry, (int)) or isinstance(retry, (urllib3.util.Retry))
|
||||
self.__requester = Requester(login_or_token, password, jwt, base_url, timeout, client_id, client_secret, user_agent, per_page, api_preview, verify, retry)
|
||||
@@ -194,7 +196,7 @@ class Github(object):
|
||||
:rtype: :class:`github.License.License`
|
||||
"""
|
||||
|
||||
assert isinstance(key, (str, unicode)), key
|
||||
assert isinstance(key, (str, six.text_type)), key
|
||||
headers, data = self.__requester.requestJsonAndCheck(
|
||||
"GET",
|
||||
"/licenses/" + key
|
||||
@@ -222,7 +224,7 @@ class Github(object):
|
||||
:param login: string
|
||||
:rtype: :class:`github.NamedUser.NamedUser`
|
||||
"""
|
||||
assert login is github.GithubObject.NotSet or isinstance(login, (str, unicode)), login
|
||||
assert login is github.GithubObject.NotSet or isinstance(login, (str, six.text_type)), login
|
||||
if login is github.GithubObject.NotSet:
|
||||
return AuthenticatedUser.AuthenticatedUser(self.__requester, {}, {"url": "/user"}, completed=False)
|
||||
else:
|
||||
@@ -238,7 +240,7 @@ class Github(object):
|
||||
:param since: integer
|
||||
:rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.NamedUser.NamedUser`
|
||||
"""
|
||||
assert since is github.GithubObject.NotSet or isinstance(since, (int, long)), since
|
||||
assert since is github.GithubObject.NotSet or isinstance(since, six.integer_types), since
|
||||
url_parameters = dict()
|
||||
if since is not github.GithubObject.NotSet:
|
||||
url_parameters["since"] = since
|
||||
@@ -255,7 +257,7 @@ class Github(object):
|
||||
:param login: string
|
||||
:rtype: :class:`github.Organization.Organization`
|
||||
"""
|
||||
assert isinstance(login, (str, unicode)), login
|
||||
assert isinstance(login, (str, six.text_type)), login
|
||||
headers, data = self.__requester.requestJsonAndCheck(
|
||||
"GET",
|
||||
"/orgs/" + login
|
||||
@@ -268,7 +270,7 @@ class Github(object):
|
||||
:param since: integer
|
||||
:rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.Organization.Organization`
|
||||
"""
|
||||
assert since is github.GithubObject.NotSet or isinstance(since, (int, long)), since
|
||||
assert since is github.GithubObject.NotSet or isinstance(since, six.integer_types), since
|
||||
url_parameters = dict()
|
||||
if since is not github.GithubObject.NotSet:
|
||||
url_parameters["since"] = since
|
||||
@@ -284,8 +286,8 @@ class Github(object):
|
||||
:calls: `GET /repos/:owner/:repo <http://developer.github.com/v3/repos>`_ or `GET /repositories/:id <http://developer.github.com/v3/repos>`_
|
||||
:rtype: :class:`github.Repository.Repository`
|
||||
"""
|
||||
assert isinstance(full_name_or_id, (str, unicode, int, long)), full_name_or_id
|
||||
url_base = "/repositories/" if isinstance(full_name_or_id, int) or isinstance(full_name_or_id, long) else "/repos/"
|
||||
assert isinstance(full_name_or_id, (str, six.text_type, int, int)), full_name_or_id
|
||||
url_base = "/repositories/" if isinstance(full_name_or_id, int) or isinstance(full_name_or_id, int) else "/repos/"
|
||||
url = "%s%s" % (url_base, full_name_or_id)
|
||||
if lazy:
|
||||
return Repository.Repository(self.__requester, {}, {"url": url}, completed=False)
|
||||
@@ -302,7 +304,7 @@ class Github(object):
|
||||
:param visibility: string ('all','public')
|
||||
:rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.Repository.Repository`
|
||||
"""
|
||||
assert since is github.GithubObject.NotSet or isinstance(since, (int, long)), since
|
||||
assert since is github.GithubObject.NotSet or isinstance(since, six.integer_types), since
|
||||
url_parameters = dict()
|
||||
if since is not github.GithubObject.NotSet:
|
||||
url_parameters["since"] = since
|
||||
@@ -335,7 +337,7 @@ class Github(object):
|
||||
:param id: string
|
||||
:rtype: :class:`github.Gist.Gist`
|
||||
"""
|
||||
assert isinstance(id, (str, unicode)), id
|
||||
assert isinstance(id, (str, six.text_type)), id
|
||||
headers, data = self.__requester.requestJsonAndCheck(
|
||||
"GET",
|
||||
"/gists/" + id
|
||||
@@ -368,7 +370,7 @@ class Github(object):
|
||||
:param qualifiers: keyword dict query qualifiers
|
||||
:rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.Repository.Repository`
|
||||
"""
|
||||
assert isinstance(query, (str, unicode)), query
|
||||
assert isinstance(query, (str, six.text_type)), query
|
||||
url_parameters = dict()
|
||||
if sort is not github.GithubObject.NotSet: # pragma no branch (Should be covered)
|
||||
assert sort in ('stars', 'forks', 'updated'), sort
|
||||
@@ -403,7 +405,7 @@ class Github(object):
|
||||
:param qualifiers: keyword dict query qualifiers
|
||||
:rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.NamedUser.NamedUser`
|
||||
"""
|
||||
assert isinstance(query, (str, unicode)), query
|
||||
assert isinstance(query, (str, six.text_type)), query
|
||||
url_parameters = dict()
|
||||
if sort is not github.GithubObject.NotSet:
|
||||
assert sort in ('followers', 'repositories', 'joined'), sort
|
||||
@@ -438,7 +440,7 @@ class Github(object):
|
||||
:param qualifiers: keyword dict query qualifiers
|
||||
:rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.Issue.Issue`
|
||||
"""
|
||||
assert isinstance(query, (str, unicode)), query
|
||||
assert isinstance(query, (str, six.text_type)), query
|
||||
url_parameters = dict()
|
||||
if sort is not github.GithubObject.NotSet:
|
||||
assert sort in ('comments', 'created', 'updated'), sort
|
||||
@@ -474,7 +476,7 @@ class Github(object):
|
||||
:param qualifiers: keyword dict query qualifiers
|
||||
:rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.ContentFile.ContentFile`
|
||||
"""
|
||||
assert isinstance(query, (str, unicode)), query
|
||||
assert isinstance(query, (str, six.text_type)), query
|
||||
url_parameters = dict()
|
||||
if sort is not github.GithubObject.NotSet: # pragma no branch (Should be covered)
|
||||
assert sort in ('indexed',), sort
|
||||
@@ -512,7 +514,7 @@ class Github(object):
|
||||
:param qualifiers: keyword dict query qualifiers
|
||||
:rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.Commit.Commit`
|
||||
"""
|
||||
assert isinstance(query, (str, unicode)), query
|
||||
assert isinstance(query, (str, six.text_type)), query
|
||||
url_parameters = dict()
|
||||
if sort is not github.GithubObject.NotSet: # pragma no branch (Should be covered)
|
||||
assert sort in ('author-date', 'committer-date'), sort
|
||||
@@ -548,7 +550,7 @@ class Github(object):
|
||||
:param qualifiers: keyword dict query qualifiers
|
||||
:rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.Topic.Topic`
|
||||
"""
|
||||
assert isinstance(query, (str, unicode)), query
|
||||
assert isinstance(query, (str, six.text_type)), query
|
||||
url_parameters = dict()
|
||||
|
||||
query_chunks = []
|
||||
@@ -578,7 +580,7 @@ class Github(object):
|
||||
:param context: :class:`github.Repository.Repository`
|
||||
:rtype: string
|
||||
"""
|
||||
assert isinstance(text, (str, unicode)), text
|
||||
assert isinstance(text, (str, six.text_type)), text
|
||||
assert context is github.GithubObject.NotSet or isinstance(context, github.Repository.Repository), context
|
||||
post_parameters = {
|
||||
"text": text
|
||||
@@ -599,7 +601,7 @@ class Github(object):
|
||||
:param name: string
|
||||
:rtype: :class:`github.HookDescription.HookDescription`
|
||||
"""
|
||||
assert isinstance(name, (str, unicode)), name
|
||||
assert isinstance(name, (str, six.text_type)), name
|
||||
headers, attributes = self.__requester.requestJsonAndCheck(
|
||||
"GET",
|
||||
"/hooks/" + name
|
||||
@@ -633,7 +635,7 @@ class Github(object):
|
||||
:calls: `GET /gitignore/templates/:name <http://developer.github.com/v3/gitignore>`_
|
||||
:rtype: :class:`github.GitignoreTemplate.GitignoreTemplate`
|
||||
"""
|
||||
assert isinstance(name, (str, unicode)), name
|
||||
assert isinstance(name, (str, six.text_type)), name
|
||||
headers, attributes = self.__requester.requestJsonAndCheck(
|
||||
"GET",
|
||||
"/gitignore/templates/" + name
|
||||
@@ -707,7 +709,7 @@ class GithubIntegration(object):
|
||||
self.base_url = base_url
|
||||
self.integration_id = integration_id
|
||||
self.private_key = private_key
|
||||
assert isinstance(base_url, (str, unicode)), base_url
|
||||
assert isinstance(base_url, (str, six.text_type)), base_url
|
||||
|
||||
def create_jwt(self, expiration=60):
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user