Kaydet (Commit) 80573bb9 authored tarafından Serhiy Storchaka's avatar Serhiy Storchaka

Issue #15267: HTTPConnection.request() now is compatibile with old-style

classes (such as TemporaryFile).  Original patch by Atsuo Ishimoto.
üst b70091a8
...@@ -1063,7 +1063,7 @@ class HTTPConnection: ...@@ -1063,7 +1063,7 @@ class HTTPConnection:
elif body is not None: elif body is not None:
try: try:
thelen = str(len(body)) thelen = str(len(body))
except TypeError: except (TypeError, AttributeError):
# If this is a file-like object, try to # If this is a file-like object, try to
# fstat its file descriptor # fstat its file descriptor
try: try:
......
...@@ -5,6 +5,7 @@ import StringIO ...@@ -5,6 +5,7 @@ import StringIO
import socket import socket
import errno import errno
import os import os
import tempfile
import unittest import unittest
TestCase = unittest.TestCase TestCase = unittest.TestCase
...@@ -399,6 +400,22 @@ class BasicTest(TestCase): ...@@ -399,6 +400,22 @@ class BasicTest(TestCase):
conn.sock = sock conn.sock = sock
conn.request('GET', '/foo', body) conn.request('GET', '/foo', body)
self.assertTrue(sock.data.startswith(expected)) self.assertTrue(sock.data.startswith(expected))
self.assertIn('def test_send_file', sock.data)
def test_send_tempfile(self):
expected = ('GET /foo HTTP/1.1\r\nHost: example.com\r\n'
'Accept-Encoding: identity\r\nContent-Length: 9\r\n\r\n'
'fake\ndata')
with tempfile.TemporaryFile() as body:
body.write('fake\ndata')
body.seek(0)
conn = httplib.HTTPConnection('example.com')
sock = FakeSocket(body)
conn.sock = sock
conn.request('GET', '/foo', body)
self.assertEqual(sock.data, expected)
def test_send(self): def test_send(self):
expected = 'this is a test this is only a test' expected = 'this is a test this is only a test'
......
...@@ -13,6 +13,9 @@ Core and Builtins ...@@ -13,6 +13,9 @@ Core and Builtins
Library Library
------- -------
- Issue #15267: HTTPConnection.request() now is compatibile with old-style
classes (such as TemporaryFile). Original patch by Atsuo Ishimoto.
- Issue #20014: array.array() now accepts unicode typecodes. Based on patch by - Issue #20014: array.array() now accepts unicode typecodes. Based on patch by
Vajrasky Kok. Vajrasky Kok.
......
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