Commit ead1d62d authored by Antoine Pitrou's avatar Antoine Pitrou

[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.
........
parent 8da3cac4
...@@ -726,7 +726,14 @@ class HTTPConnection: ...@@ -726,7 +726,14 @@ class HTTPConnection:
if self.debuglevel > 0: if self.debuglevel > 0:
print("sendIng a read()able") print("sendIng a read()able")
encode = False encode = False
if "b" not in str.mode: 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 encode = True
if self.debuglevel > 0: if self.debuglevel > 0:
print("encoding file using iso-8859-1") print("encoding file using iso-8859-1")
......
import errno import errno
from http import client from http import client
import io import io
import array
import socket import socket
from unittest import TestCase from unittest import TestCase
...@@ -174,6 +175,20 @@ class BasicTest(TestCase): ...@@ -174,6 +175,20 @@ class BasicTest(TestCase):
self.assertTrue(sock.data.startswith(expected), '%r != %r' % self.assertTrue(sock.data.startswith(expected), '%r != %r' %
(sock.data[:len(expected)], expected)) (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): def test_chunked(self):
chunked_start = ( chunked_start = (
'HTTP/1.1 200 OK\r\n' 'HTTP/1.1 200 OK\r\n'
......
...@@ -481,6 +481,7 @@ Nick Mathewson ...@@ -481,6 +481,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
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment