summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAntoine Pitrou <solipsis@pitrou.net>2009-09-29 17:48:18 (GMT)
committerAntoine Pitrou <solipsis@pitrou.net>2009-09-29 17:48:18 (GMT)
commit7248178cd9efb2e568ba71f3293f3be23ef05e5d (patch)
treee5195e03b35fba77f3d36678239498703ce3fc51
parent9ebd242fbbd2c52fcf314e22f6b5bf57954d52cd (diff)
downloadcpython-7248178cd9efb2e568ba71f3293f3be23ef05e5d.zip
cpython-7248178cd9efb2e568ba71f3293f3be23ef05e5d.tar.gz
cpython-7248178cd9efb2e568ba71f3293f3be23ef05e5d.tar.bz2
Issue #6790: Make it possible again to pass an `array.array` to
`httplib.HTTPConnection.send`. Patch by Kirk McDonald.
-rw-r--r--Lib/httplib.py3
-rw-r--r--Lib/test/test_httplib.py17
-rw-r--r--Misc/ACKS1
-rw-r--r--Misc/NEWS3
4 files changed, 22 insertions, 2 deletions
diff --git a/Lib/httplib.py b/Lib/httplib.py
index 30cabce..a83245b 100644
--- a/Lib/httplib.py
+++ b/Lib/httplib.py
@@ -66,6 +66,7 @@ Req-started-unread-response _CS_REQ_STARTED <response_class>
Req-sent-unread-response _CS_REQ_SENT <response_class>
"""
+from array import array
import socket
from sys import py3kwarning
from urlparse import urlsplit
@@ -747,7 +748,7 @@ class HTTPConnection:
print "send:", repr(str)
try:
blocksize=8192
- if hasattr(str,'read') :
+ if hasattr(str,'read') and not isinstance(str, array):
if self.debuglevel > 0: print "sendIng a read()able"
data=str.read(blocksize)
while data:
diff --git a/Lib/test/test_httplib.py b/Lib/test/test_httplib.py
index 77e9887..cd54323 100644
--- a/Lib/test/test_httplib.py
+++ b/Lib/test/test_httplib.py
@@ -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'
diff --git a/Misc/ACKS b/Misc/ACKS
index 4889be8..1acbf2f 100644
--- a/Misc/ACKS
+++ b/Misc/ACKS
@@ -477,6 +477,7 @@ Nick Mathewson
Graham Matthews
Dieter Maurer
Arnaud Mazin
+Kirk McDonald
Chris McDonough
Greg McFarlane
Alan McIntyre
diff --git a/Misc/NEWS b/Misc/NEWS
index 98beb4e..cb24b3f 100644
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -383,6 +383,9 @@ Core and Builtins
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
and other platforms, when using a non-gcc compiler. Patch by egreen.