Issue #6790: Make it possible again to pass an `array.array` to

`httplib.HTTPConnection.send`. Patch by Kirk McDonald.
This commit is contained in:
Antoine Pitrou 2009-09-29 17:48:18 +00:00
parent 9ebd242fbb
commit 7248178cd9
4 changed files with 22 additions and 2 deletions

View File

@ -66,6 +66,7 @@ Req-started-unread-response _CS_REQ_STARTED <response_class>
Req-sent-unread-response _CS_REQ_SENT <response_class> Req-sent-unread-response _CS_REQ_SENT <response_class>
""" """
from array import array
import socket import socket
from sys import py3kwarning from sys import py3kwarning
from urlparse import urlsplit from urlparse import urlsplit
@ -747,7 +748,7 @@ class HTTPConnection:
print "send:", repr(str) print "send:", repr(str)
try: try:
blocksize=8192 blocksize=8192
if hasattr(str,'read') : if hasattr(str,'read') and not isinstance(str, array):
if self.debuglevel > 0: print "sendIng a read()able" if self.debuglevel > 0: print "sendIng a read()able"
data=str.read(blocksize) data=str.read(blocksize)
while data: while data:

View File

@ -1,3 +1,4 @@
import array
import httplib import httplib
import StringIO import StringIO
import socket import socket
@ -15,7 +16,7 @@ class FakeSocket:
self.data = '' self.data = ''
def sendall(self, data): def sendall(self, data):
self.data += data self.data += ''.join(data)
def makefile(self, mode, bufsize=None): def makefile(self, mode, bufsize=None):
if mode != 'r' and mode != 'rb': if mode != 'r' and mode != 'rb':
@ -162,6 +163,20 @@ class BasicTest(TestCase):
conn.request('GET', '/foo', body) conn.request('GET', '/foo', body)
self.assertTrue(sock.data.startswith(expected)) 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): def test_chunked(self):
chunked_start = ( chunked_start = (
'HTTP/1.1 200 OK\r\n' 'HTTP/1.1 200 OK\r\n'

View File

@ -477,6 +477,7 @@ Nick Mathewson
Graham Matthews Graham Matthews
Dieter Maurer Dieter Maurer
Arnaud Mazin Arnaud Mazin
Kirk McDonald
Chris McDonough Chris McDonough
Greg McFarlane Greg McFarlane
Alan McIntyre Alan McIntyre

View File

@ -383,6 +383,9 @@ Core and Builtins
Library Library
------- -------
- Issue #6790: Make it possible again to pass an `array.array` to
`httplib.HTTPConnection.send`. Patch by Kirk McDonald.
- Issue #6236, #6348: Fix various failures in the `io` module under AIX - Issue #6236, #6348: Fix various failures in the `io` module under AIX
and other platforms, when using a non-gcc compiler. Patch by egreen. and other platforms, when using a non-gcc compiler. Patch by egreen.