Allow body to be passed as bytes in python 3.4

Fixes #113, thanks leplatrem for the report!
This commit is contained in:
Honza Král
2014-08-23 15:25:44 -07:00
parent be1391b9ac
commit 18d6b41e82
2 changed files with 9 additions and 2 deletions
+2 -2
View File
@@ -265,8 +265,8 @@ class Transport(object):
if body is not None:
try:
body = body.encode('utf-8')
except UnicodeDecodeError:
# Python 2 and str, no need to re-encode
except (UnicodeDecodeError, AttributeError):
# bytes/str - no need to re-encode
pass
ignore = ()
+7
View File
@@ -81,6 +81,13 @@ class TestTransport(TestCase):
self.assertEquals(1, len(t.get_connection().calls))
self.assertEquals(('GET', '/', None, b'\xe4\xbd\xa0\xe5\xa5\xbd'), t.get_connection().calls[0][0])
def test_body_bytes_get_passed_untouched(self):
t = Transport([{}], connection_class=DummyConnection)
body = b'\xe4\xbd\xa0\xe5\xa5\xbd'
t.perform_request('GET', '/', body=body)
self.assertEquals(1, len(t.get_connection().calls))
self.assertEquals(('GET', '/', None, body), t.get_connection().calls[0][0])
def test_kwargs_passed_on_to_connections(self):
t = Transport([{'host': 'google.com'}], port=123)