Remove more Python version specific code (#1193)

Remove a bunch of other call sites that behaved differently between
Python 2 and 3, massively cleaning up a few messy methods.
This commit is contained in:
Steve Kowalik
2019-08-28 15:24:54 +10:00
committed by GitHub
parent 7bac694ae5
commit a0f01cf9cf
9 changed files with 44 additions and 94 deletions
+11 -24
View File
@@ -86,10 +86,10 @@
################################################################################
from __future__ import absolute_import
import sys
import six.moves.urllib.parse
import datetime
from base64 import b64encode
import collections
import github.GithubObject
import github.PaginatedList
@@ -137,8 +137,6 @@ import github.View
from . import Consts
import six
atLeastPython3 = sys.hexversion >= 0x03000000
class Repository(github.GithubObject.CompletableGithubObject):
"""
@@ -1647,14 +1645,9 @@ class Repository(github.GithubObject.CompletableGithubObject):
or isinstance(committer, github.InputGitAuthor), \
'committer must be a github.InputGitAuthor object'
if atLeastPython3:
if isinstance(content, str):
content = content.encode('utf-8')
content = b64encode(content).decode('utf-8')
else:
if isinstance(content, six.text_type):
content = content.encode('utf-8')
content = b64encode(content)
content = b64encode(bytearray(content, 'utf-8'))
if isinstance(content, bytes):
content = content.decode('utf-8')
put_parameters = {'message': message, 'content': content}
if branch is not github.GithubObject.NotSet:
@@ -1709,14 +1702,9 @@ class Repository(github.GithubObject.CompletableGithubObject):
or isinstance(committer, github.InputGitAuthor), \
'committer must be a github.InputGitAuthor object'
if atLeastPython3:
if isinstance(content, str):
content = content.encode('utf-8')
content = b64encode(content).decode('utf-8')
else:
if isinstance(content, six.text_type):
content = content.encode('utf-8')
content = b64encode(content)
content = b64encode(bytearray(content, 'utf-8'))
if isinstance(content, bytes):
content = content.decode('utf-8')
put_parameters = {'message': message, 'content': content,
'sha': sha}
@@ -2789,11 +2777,10 @@ class Repository(github.GithubObject.CompletableGithubObject):
assert isinstance(callback, (str, six.text_type)), callback
assert secret is github.GithubObject.NotSet or isinstance(secret, (str, six.text_type)), secret
post_parameters = {
"hub.mode": mode,
"hub.topic": "https://github.com/" + self.full_name + "/events/" + event,
"hub.callback": callback,
}
post_parameters = collections.OrderedDict()
post_parameters["hub.callback"] = callback
post_parameters["hub.topic"] = "https://github.com/" + self.full_name + "/events/" + event
post_parameters["hub.mode"] = mode
if secret is not github.GithubObject.NotSet:
post_parameters["hub.secret"] = secret