[Python-checkins] r75142 - in python/branches/release31-maint: Lib/http/client.py Lib/test/test_httplib.py Misc/ACKS

antoine.pitrou python-checkins at python.org
Tue Sep 29 21:02:24 CEST 2009


Author: antoine.pitrou
Date: Tue Sep 29 21:02:24 2009
New Revision: 75142

Log:
Merged revisions 75137 via svnmerge from 
svn+ssh://pythondev@svn.python.org/python/branches/py3k

................
  r75137 | antoine.pitrou | 2009-09-29 20:44:53 +0200 (mar., 29 sept. 2009) | 14 lines
  
  [NOTE: the original bug doesn't exist in py3k but this adds Kirk's tests and fixes
  another bug in the process]
  
  
  Merged revisions 75134 via svnmerge from 
  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.
  ........
................


Modified:
   python/branches/release31-maint/   (props changed)
   python/branches/release31-maint/Lib/http/client.py
   python/branches/release31-maint/Lib/test/test_httplib.py
   python/branches/release31-maint/Misc/ACKS

Modified: python/branches/release31-maint/Lib/http/client.py
==============================================================================
--- python/branches/release31-maint/Lib/http/client.py	(original)
+++ python/branches/release31-maint/Lib/http/client.py	Tue Sep 29 21:02:24 2009
@@ -726,10 +726,17 @@
             if self.debuglevel > 0:
                 print("sendIng a read()able")
             encode = False
-            if "b" not in str.mode:
-                encode = True
-                if self.debuglevel > 0:
-                    print("encoding file using iso-8859-1")
+            try:
+                mode = str.mode
+            except AttributeError:
+                # io.BytesIO and other file-like objects don't have a `mode`
+                # attribute.
+                pass
+            else:
+                if "b" not in mode:
+                    encode = True
+                    if self.debuglevel > 0:
+                        print("encoding file using iso-8859-1")
             while 1:
                 data = str.read(blocksize)
                 if not data:

Modified: python/branches/release31-maint/Lib/test/test_httplib.py
==============================================================================
--- python/branches/release31-maint/Lib/test/test_httplib.py	(original)
+++ python/branches/release31-maint/Lib/test/test_httplib.py	Tue Sep 29 21:02:24 2009
@@ -1,6 +1,7 @@
 import errno
 from http import client
 import io
+import array
 import socket
 
 from unittest import TestCase
@@ -174,6 +175,20 @@
         self.assertTrue(sock.data.startswith(expected), '%r != %r' %
                 (sock.data[:len(expected)], expected))
 
+    def test_send(self):
+        expected = b'this is a test this is only a test'
+        conn = client.HTTPConnection('example.com')
+        sock = FakeSocket(None)
+        conn.sock = sock
+        conn.send(expected)
+        self.assertEquals(expected, sock.data)
+        sock.data = b''
+        conn.send(array.array('b', expected))
+        self.assertEquals(expected, sock.data)
+        sock.data = b''
+        conn.send(io.BytesIO(expected))
+        self.assertEquals(expected, sock.data)
+
     def test_chunked(self):
         chunked_start = (
             'HTTP/1.1 200 OK\r\n'

Modified: python/branches/release31-maint/Misc/ACKS
==============================================================================
--- python/branches/release31-maint/Misc/ACKS	(original)
+++ python/branches/release31-maint/Misc/ACKS	Tue Sep 29 21:02:24 2009
@@ -477,6 +477,7 @@
 Graham Matthews
 Dieter Maurer
 Arnaud Mazin
+Kirk McDonald
 Chris McDonough
 Greg McFarlane
 Alan McIntyre


More information about the Python-checkins mailing list