mirror of
https://github.com/status-im/PyGithub.git
synced 2026-08-31 10:51:14 +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:
+28
-26
@@ -42,8 +42,9 @@
|
||||
# #
|
||||
################################################################################
|
||||
|
||||
from __future__ import absolute_import
|
||||
import datetime
|
||||
import urllib
|
||||
import six.moves.urllib.request, six.moves.urllib.parse, six.moves.urllib.error
|
||||
import github.GithubObject
|
||||
import github.PaginatedList
|
||||
|
||||
@@ -56,7 +57,8 @@ import github.IssueComment
|
||||
import github.Commit
|
||||
import github.PullRequestReview
|
||||
|
||||
import Consts
|
||||
from . import Consts
|
||||
import six
|
||||
|
||||
|
||||
class PullRequest(github.GithubObject.CompletableGithubObject):
|
||||
@@ -386,10 +388,10 @@ class PullRequest(github.GithubObject.CompletableGithubObject):
|
||||
:param position: integer
|
||||
:rtype: :class:`github.PullRequestComment.PullRequestComment`
|
||||
"""
|
||||
assert isinstance(body, (str, unicode)), body
|
||||
assert isinstance(body, (str, six.text_type)), body
|
||||
assert isinstance(commit_id, github.Commit.Commit), commit_id
|
||||
assert isinstance(path, (str, unicode)), path
|
||||
assert isinstance(position, (int, long)), position
|
||||
assert isinstance(path, (str, six.text_type)), path
|
||||
assert isinstance(position, six.integer_types), position
|
||||
post_parameters = {
|
||||
"body": body,
|
||||
"commit_id": commit_id._identity,
|
||||
@@ -409,7 +411,7 @@ class PullRequest(github.GithubObject.CompletableGithubObject):
|
||||
:param body: string
|
||||
:rtype: :class:`github.IssueComment.IssueComment`
|
||||
"""
|
||||
assert isinstance(body, (str, unicode)), body
|
||||
assert isinstance(body, (str, six.text_type)), body
|
||||
post_parameters = {
|
||||
"body": body,
|
||||
}
|
||||
@@ -459,10 +461,10 @@ class PullRequest(github.GithubObject.CompletableGithubObject):
|
||||
"""
|
||||
post_parameters = dict()
|
||||
if reviewers is not github.GithubObject.NotSet:
|
||||
assert all(isinstance(element, (str, unicode)) for element in reviewers), reviewers
|
||||
assert all(isinstance(element, (str, six.text_type)) for element in reviewers), reviewers
|
||||
post_parameters["reviewers"] = reviewers
|
||||
if team_reviewers is not github.GithubObject.NotSet:
|
||||
assert all(isinstance(element, (str, unicode)) for element in team_reviewers), team_reviewers
|
||||
assert all(isinstance(element, (str, six.text_type)) for element in team_reviewers), team_reviewers
|
||||
post_parameters["team_reviewers"] = team_reviewers
|
||||
headers, data = self._requester.requestJsonAndCheck(
|
||||
"POST",
|
||||
@@ -479,10 +481,10 @@ class PullRequest(github.GithubObject.CompletableGithubObject):
|
||||
"""
|
||||
post_parameters = dict()
|
||||
if reviewers is not github.GithubObject.NotSet:
|
||||
assert all(isinstance(element, (str, unicode)) for element in reviewers), reviewers
|
||||
assert all(isinstance(element, (str, six.text_type)) for element in reviewers), reviewers
|
||||
post_parameters["reviewers"] = reviewers
|
||||
if team_reviewers is not github.GithubObject.NotSet:
|
||||
assert all(isinstance(element, (str, unicode)) for element in team_reviewers), team_reviewers
|
||||
assert all(isinstance(element, (str, six.text_type)) for element in team_reviewers), team_reviewers
|
||||
post_parameters["team_reviewers"] = team_reviewers
|
||||
headers, data = self._requester.requestJsonAndCheck(
|
||||
"DELETE",
|
||||
@@ -499,10 +501,10 @@ class PullRequest(github.GithubObject.CompletableGithubObject):
|
||||
:param base: string
|
||||
:rtype: None
|
||||
"""
|
||||
assert title is github.GithubObject.NotSet or isinstance(title, (str, unicode)), title
|
||||
assert body is github.GithubObject.NotSet or isinstance(body, (str, unicode)), body
|
||||
assert state is github.GithubObject.NotSet or isinstance(state, (str, unicode)), state
|
||||
assert base is github.GithubObject.NotSet or isinstance(base, (str, unicode)), base
|
||||
assert title is github.GithubObject.NotSet or isinstance(title, (str, six.text_type)), title
|
||||
assert body is github.GithubObject.NotSet or isinstance(body, (str, six.text_type)), body
|
||||
assert state is github.GithubObject.NotSet or isinstance(state, (str, six.text_type)), state
|
||||
assert base is github.GithubObject.NotSet or isinstance(base, (str, six.text_type)), base
|
||||
post_parameters = dict()
|
||||
if title is not github.GithubObject.NotSet:
|
||||
post_parameters["title"] = title
|
||||
@@ -533,7 +535,7 @@ class PullRequest(github.GithubObject.CompletableGithubObject):
|
||||
:param id: integer
|
||||
:rtype: :class:`github.PullRequestComment.PullRequestComment`
|
||||
"""
|
||||
assert isinstance(id, (int, long)), id
|
||||
assert isinstance(id, six.integer_types), id
|
||||
headers, data = self._requester.requestJsonAndCheck(
|
||||
"GET",
|
||||
self._parentUrl(self.url) + "/comments/" + str(id)
|
||||
@@ -572,7 +574,7 @@ class PullRequest(github.GithubObject.CompletableGithubObject):
|
||||
:param id: integer
|
||||
:rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.PullRequestComment.PullRequestComment`
|
||||
"""
|
||||
assert isinstance(id, (int, long)), id
|
||||
assert isinstance(id, six.integer_types), id
|
||||
return github.PaginatedList.PaginatedList(
|
||||
github.PullRequestComment.PullRequestComment,
|
||||
self._requester,
|
||||
@@ -610,7 +612,7 @@ class PullRequest(github.GithubObject.CompletableGithubObject):
|
||||
:param id: integer
|
||||
:rtype: :class:`github.IssueComment.IssueComment`
|
||||
"""
|
||||
assert isinstance(id, (int, long)), id
|
||||
assert isinstance(id, six.integer_types), id
|
||||
headers, data = self._requester.requestJsonAndCheck(
|
||||
"GET",
|
||||
self._parentUrl(self.issue_url) + "/comments/" + str(id)
|
||||
@@ -648,7 +650,7 @@ class PullRequest(github.GithubObject.CompletableGithubObject):
|
||||
:param id: integer
|
||||
:rtype: :class:`github.PullRequestReview.PullRequestReview`
|
||||
"""
|
||||
assert isinstance(id, (int, long)), id
|
||||
assert isinstance(id, six.integer_types), id
|
||||
headers, data = self._requester.requestJsonAndCheck(
|
||||
"GET",
|
||||
self.url + "/reviews/" + str(id),
|
||||
@@ -707,7 +709,7 @@ class PullRequest(github.GithubObject.CompletableGithubObject):
|
||||
:param label: :class:`github.Label.Label` or string
|
||||
:rtype: None
|
||||
"""
|
||||
assert all(isinstance(element, (github.Label.Label, str, unicode)) for element in labels), labels
|
||||
assert all(isinstance(element, (github.Label.Label, str, six.text_type)) for element in labels), labels
|
||||
post_parameters = [label.name if isinstance(label, github.Label.Label) else label for label in labels]
|
||||
headers, data = self._requester.requestJsonAndCheck(
|
||||
"POST",
|
||||
@@ -731,11 +733,11 @@ class PullRequest(github.GithubObject.CompletableGithubObject):
|
||||
:param label: :class:`github.Label.Label` or string
|
||||
:rtype: None
|
||||
"""
|
||||
assert isinstance(label, (github.Label.Label, str, unicode)), label
|
||||
assert isinstance(label, (github.Label.Label, str, six.text_type)), label
|
||||
if isinstance(label, github.Label.Label):
|
||||
label = label._identity
|
||||
else:
|
||||
label = urllib.quote(label)
|
||||
label = six.moves.urllib.parse.quote(label)
|
||||
headers, data = self._requester.requestJsonAndCheck(
|
||||
"DELETE",
|
||||
self.issue_url + "/labels/" + label
|
||||
@@ -747,7 +749,7 @@ class PullRequest(github.GithubObject.CompletableGithubObject):
|
||||
:param labels: list of :class:`github.Label.Label` or strings
|
||||
:rtype: None
|
||||
"""
|
||||
assert all(isinstance(element, (github.Label.Label, str, unicode)) for element in labels), labels
|
||||
assert all(isinstance(element, (github.Label.Label, str, six.text_type)) for element in labels), labels
|
||||
post_parameters = [label.name if isinstance(label, github.Label.Label) else label for label in labels]
|
||||
headers, data = self._requester.requestJsonAndCheck(
|
||||
"PUT",
|
||||
@@ -772,10 +774,10 @@ class PullRequest(github.GithubObject.CompletableGithubObject):
|
||||
:param commit_message: string
|
||||
:rtype: :class:`github.PullRequestMergeStatus.PullRequestMergeStatus`
|
||||
"""
|
||||
assert commit_message is github.GithubObject.NotSet or isinstance(commit_message, (str, unicode)), commit_message
|
||||
assert commit_title is github.GithubObject.NotSet or isinstance(commit_title, (str, unicode)), commit_title
|
||||
assert merge_method is github.GithubObject.NotSet or isinstance(merge_method, (str, unicode)), merge_method
|
||||
assert sha is github.GithubObject.NotSet or isinstance(sha, (str, unicode)), sha
|
||||
assert commit_message is github.GithubObject.NotSet or isinstance(commit_message, (str, six.text_type)), commit_message
|
||||
assert commit_title is github.GithubObject.NotSet or isinstance(commit_title, (str, six.text_type)), commit_title
|
||||
assert merge_method is github.GithubObject.NotSet or isinstance(merge_method, (str, six.text_type)), merge_method
|
||||
assert sha is github.GithubObject.NotSet or isinstance(sha, (str, six.text_type)), sha
|
||||
post_parameters = dict()
|
||||
if commit_message is not github.GithubObject.NotSet:
|
||||
post_parameters["commit_message"] = commit_message
|
||||
|
||||
Reference in New Issue
Block a user