]> granicus.if.org Git - python/commitdiff
Merged revisions 75134 via svnmerge from
authorAntoine Pitrou <solipsis@pitrou.net>
Tue, 29 Sep 2009 18:14:09 +0000 (18:14 +0000)
committerAntoine Pitrou <solipsis@pitrou.net>
Tue, 29 Sep 2009 18:14:09 +0000 (18:14 +0000)
svn+ssh://pythondev@svn.python.org/python/trunk

........
  r75134 | antoine.pitrou | 2009-09-29 19:48:18 +0200 (mar., 29 sept. 2009) | 4 lines

  Issue #6790: Make it possible again to pass an `array.array` to
  `httplib.HTTPConnection.send`. Patch by Kirk McDonald.
........

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

index 3566c0eb055c6d75cdefaa94b085b4295f7be5f5..3623bc3853eb37a2f9f5d1e6a4c2168ec04d2096 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
@@ -732,7 +733,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 54a2b0ea6dcf131a7b9117e2f50197612c655ce1..252834b85629a03815a7d00469242b39d0b2ed73 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 58ce22837751dc52a904b52504d1dcfaec65a765..db058eefe81ac412eba2aa8cf8dd33736a9db94d 100644 (file)
--- a/Misc/ACKS
+++ b/Misc/ACKS
@@ -458,6 +458,7 @@ Nick Mathewson
 Graham Matthews
 Dieter Maurer
 Arnaud Mazin
+Kirk McDonald
 Chris McDonough
 Greg McFarlane
 Alan McIntyre
index 36ee04cca860d3945d73d6898edbb115fb7142f4..917e5d56edbbb16b4b456355b3cb882a985ae6cf 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -85,6 +85,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.