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):
+2 -9
View File
@@ -23,16 +23,11 @@
# #
################################################################################
import base64
import sys
import Framework
import github
import datetime
atLeastPython3 = sys.hexversion >= 0x03000000
class ContentFile(Framework.TestCase):
def setUp(self):
@@ -45,8 +40,6 @@ class ContentFile(Framework.TestCase):
self.assertEqual(self.file.size, 7531)
self.assertEqual(self.file.name, "ReadMe.md")
self.assertEqual(self.file.path, "ReadMe.md")
if atLeastPython3:
self.assertEqual(len(base64.b64decode(bytearray(self.file.content, "utf-8"))), 7531) # pragma no cover (Covered with Python 3)
else:
self.assertEqual(len(base64.b64decode(self.file.content)), 7531)
self.assertEqual(len(self.file.content), 10212)
self.assertEqual(len(self.file.decoded_content), 7531)
self.assertEqual(self.file.sha, "5628799a7d517a4aaa0c1a7004d07569cd154df0")