mirror of
https://github.com/python/cpython.git
synced 2025-08-01 07:33:08 +00:00
Issue #6790: Make it possible again to pass an array.array
to
`httplib.HTTPConnection.send`. Patch by Kirk McDonald.
This commit is contained in:
parent
9ebd242fbb
commit
7248178cd9
4 changed files with 22 additions and 2 deletions
|
@ -1,3 +1,4 @@
|
|||
import array
|
||||
import httplib
|
||||
import StringIO
|
||||
import socket
|
||||
|
@ -15,7 +16,7 @@ class FakeSocket:
|
|||
self.data = ''
|
||||
|
||||
def sendall(self, data):
|
||||
self.data += data
|
||||
self.data += ''.join(data)
|
||||
|
||||
def makefile(self, mode, bufsize=None):
|
||||
if mode != 'r' and mode != 'rb':
|
||||
|
@ -162,6 +163,20 @@ class BasicTest(TestCase):
|
|||
conn.request('GET', '/foo', body)
|
||||
self.assertTrue(sock.data.startswith(expected))
|
||||
|
||||
def test_send(self):
|
||||
expected = 'this is a test this is only a test'
|
||||
conn = httplib.HTTPConnection('example.com')
|
||||
sock = FakeSocket(None)
|
||||
conn.sock = sock
|
||||
conn.send(expected)
|
||||
self.assertEquals(expected, sock.data)
|
||||
sock.data = ''
|
||||
conn.send(array.array('c', expected))
|
||||
self.assertEquals(expected, sock.data)
|
||||
sock.data = ''
|
||||
conn.send(StringIO.StringIO(expected))
|
||||
self.assertEquals(expected, sock.data)
|
||||
|
||||
def test_chunked(self):
|
||||
chunked_start = (
|
||||
'HTTP/1.1 200 OK\r\n'
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue