diff options
-rw-r--r-- | Lib/http/client.py | 15 | ||||
-rw-r--r-- | Lib/test/test_httplib.py | 15 | ||||
-rw-r--r-- | Misc/ACKS | 1 |
3 files changed, 27 insertions, 4 deletions
diff --git a/Lib/http/client.py b/Lib/http/client.py index b7092de..fef7185 100644 --- a/Lib/http/client.py +++ b/Lib/http/client.py @@ -726,10 +726,17 @@ class HTTPConnection: if self.debuglevel > 0: print("sendIng a read()able") encode = False - if "b" not in str.mode: - encode = True - if self.debuglevel > 0: - print("encoding file using iso-8859-1") + try: + mode = str.mode + except AttributeError: + # io.BytesIO and other file-like objects don't have a `mode` + # attribute. + pass + else: + if "b" not in mode: + encode = True + if self.debuglevel > 0: + print("encoding file using iso-8859-1") while 1: data = str.read(blocksize) if not data: diff --git a/Lib/test/test_httplib.py b/Lib/test/test_httplib.py index 2d76f7a..37cda5d 100644 --- a/Lib/test/test_httplib.py +++ b/Lib/test/test_httplib.py @@ -1,6 +1,7 @@ import errno from http import client import io +import array import socket from unittest import TestCase @@ -174,6 +175,20 @@ class BasicTest(TestCase): self.assertTrue(sock.data.startswith(expected), '%r != %r' % (sock.data[:len(expected)], expected)) + def test_send(self): + expected = b'this is a test this is only a test' + conn = client.HTTPConnection('example.com') + sock = FakeSocket(None) + conn.sock = sock + conn.send(expected) + self.assertEquals(expected, sock.data) + sock.data = b'' + conn.send(array.array('b', expected)) + self.assertEquals(expected, sock.data) + sock.data = b'' + conn.send(io.BytesIO(expected)) + self.assertEquals(expected, sock.data) + def test_chunked(self): chunked_start = ( 'HTTP/1.1 200 OK\r\n' @@ -481,6 +481,7 @@ Nick Mathewson Graham Matthews Dieter Maurer Arnaud Mazin +Kirk McDonald Chris McDonough Greg McFarlane Alan McIntyre |