Fix ContentFile.decoded_content for Python 3.0 to 3.2

This commit is contained in:
Vincent Jacques
2014-03-16 10:01:47 -07:00
parent 95cd63f08c
commit e79dd520e3
2 changed files with 11 additions and 10 deletions
+9 -1
View File
@@ -25,11 +25,15 @@
################################################################################
import base64
import sys
import github.GithubObject
import github.Repository
atLeastPython3 = sys.hexversion >= 0x03000000
class ContentFile(github.GithubObject.CompletableGithubObject):
"""
This class represents ContentFiles as returned for example by http://developer.github.com/v3/todo
@@ -46,7 +50,11 @@ class ContentFile(github.GithubObject.CompletableGithubObject):
@property
def decoded_content(self):
assert self.encoding == "base64", "unsupported encoding: %s" % self.encoding
return base64.b64decode(self.content)
if atLeastPython3:
content = bytearray(self.content, "utf-8") # pragma no cover (covered by tests with Python 3.2)
else:
content = self.content
return base64.b64decode(content)
@property
def encoding(self):