b64encode: no support for bytearray (py2.6 problems)

This commit is contained in:
Jakub Warmuz 2015-07-12 15:20:25 +00:00
parent 596132292a
commit 5859e87ced
No known key found for this signature in database
GPG key ID: 2A7BAD3A489B52EA
2 changed files with 3 additions and 7 deletions

View file

@ -22,7 +22,7 @@ def b64encode(data):
"""JOSE Base64 encode.
:param data: Data to be encoded.
:type data: `bytes` or `bytearray`
:type data: `bytes`
:returns: JOSE Base64 string.
:rtype: bytes
@ -30,9 +30,8 @@ def b64encode(data):
:raises TypeError: if `data` is of incorrect type
"""
if not isinstance(data, (six.binary_type, bytearray)):
raise TypeError('argument should be {0} or bytearray'.format(
six.binary_type))
if not isinstance(data, six.binary_type):
raise TypeError('argument should be {0}'.format(six.binary_type))
return base64.urlsafe_b64encode(data).rstrip(b'=')

View file

@ -39,9 +39,6 @@ class B64EncodeTest(unittest.TestCase):
for text, (b64, _) in six.iteritems(B64_PADDING_EXAMPLES):
self.assertEqual(self._call(text), b64)
def test_bytearray_ok(self):
self.assertEqual(self._call(bytearray(b'foo')), b'Zm9v')
def test_unicode_fails_with_type_error(self):
self.assertRaises(TypeError, self._call, u'some unicode')