mirror of
https://github.com/status-im/PyGithub.git
synced 2026-09-01 03:11:09 +00:00
Fix uploading binary files on Python 3 (#621)
There is a bit of logic for Python 2 that detects if you're uploading string or bytes, but this is missing for Python 3.
This commit is contained in:
committed by
Jason White
parent
84b43da76c
commit
317079efff
@@ -1283,7 +1283,7 @@ class Repository(github.GithubObject.CompletableGithubObject):
|
||||
'path must be str/unicode object'
|
||||
assert isinstance(message, (str, unicode)), \
|
||||
'message must be str/unicode object'
|
||||
assert isinstance(content, (str, unicode)), \
|
||||
assert isinstance(content, (str, unicode, bytes)), \
|
||||
'content must be a str/unicode object'
|
||||
assert branch is github.GithubObject.NotSet \
|
||||
or isinstance(branch, (str, unicode)), \
|
||||
@@ -1296,7 +1296,9 @@ class Repository(github.GithubObject.CompletableGithubObject):
|
||||
'committer must be a github.InputGitAuthor object'
|
||||
|
||||
if atLeastPython3:
|
||||
content = b64encode(content.encode('utf-8')).decode('utf-8')
|
||||
if isinstance(content, str):
|
||||
content = content.encode('utf-8')
|
||||
content = b64encode(content).decode('utf-8')
|
||||
else:
|
||||
if isinstance(content, unicode):
|
||||
content = content.encode('utf-8')
|
||||
@@ -1338,7 +1340,7 @@ class Repository(github.GithubObject.CompletableGithubObject):
|
||||
'path must be str/unicode object'
|
||||
assert isinstance(message, (str, unicode)), \
|
||||
'message must be str/unicode object'
|
||||
assert isinstance(content, (str, unicode)), \
|
||||
assert isinstance(content, (str, unicode, bytes)), \
|
||||
'content must be a str/unicode object'
|
||||
assert isinstance(sha, (str, unicode)), \
|
||||
'sha must be a str/unicode object'
|
||||
@@ -1353,7 +1355,9 @@ class Repository(github.GithubObject.CompletableGithubObject):
|
||||
'committer must be a github.InputGitAuthor object'
|
||||
|
||||
if atLeastPython3:
|
||||
content = b64encode(content.encode('utf-8')).decode('utf-8')
|
||||
if isinstance(content, str):
|
||||
content = content.encode('utf-8')
|
||||
content = b64encode(content).decode('utf-8')
|
||||
else:
|
||||
if isinstance(content, unicode):
|
||||
content = content.encode('utf-8')
|
||||
|
||||
Reference in New Issue
Block a user