]> granicus.if.org Git - python/commitdiff
Issue #6790: Make it possible again to pass an `array.array` to
authorAntoine Pitrou <solipsis@pitrou.net>
Tue, 29 Sep 2009 17:48:18 +0000 (17:48 +0000)
committerAntoine Pitrou <solipsis@pitrou.net>
Tue, 29 Sep 2009 17:48:18 +0000 (17:48 +0000)
`httplib.HTTPConnection.send`. Patch by Kirk McDonald.

Lib/httplib.py
Lib/test/test_httplib.py
Misc/ACKS
Misc/NEWS

index 30cabcef2bad6fe87b88192b9a1ccba545c02dac..a83245bb9393230f0222a996554b4712ee854d03 100644 (file)
@@ -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:
index 77e9887cc58d89f570d7672173e70cc38d468658..cd54323f1ae26d93d22ecee0e19c53538bdd9005 100644 (file)
@@ -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'
index 4889be8aeece15a2e491fb0a41e013dd96dc31a8..1acbf2ff1c39f7dfe4b24c8c6be6b23b43321299 100644 (file)
--- 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
index 98beb4e313374b96ef80893ca5b5f8fdc7779fa2..cb24b3f908d18345ce15f8733b5a8f8600f78da1 100644 (file)
--- 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.