[Python-checkins] r85205 - in python/branches/py3k/Lib: http/client.py test/test_httplib.py
senthil.kumaran
python-checkins at python.org
Sun Oct 3 20:22:42 CEST 2010
Author: senthil.kumaran
Date: Sun Oct 3 20:22:42 2010
New Revision: 85205
Log:
Fix Issue10012 - httplib headers, which are (sometimes mistakenly) int are explicitly cast to str (bytes - in py3k).
Modified:
python/branches/py3k/Lib/http/client.py
python/branches/py3k/Lib/test/test_httplib.py
Modified: python/branches/py3k/Lib/http/client.py
==============================================================================
--- python/branches/py3k/Lib/http/client.py (original)
+++ python/branches/py3k/Lib/http/client.py Sun Oct 3 20:22:42 2010
@@ -917,6 +917,8 @@
for i, one_value in enumerate(values):
if hasattr(one_value, 'encode'):
values[i] = one_value.encode('ascii')
+ elif isinstance(one_value, int):
+ values[i] = str(one_value).encode('ascii')
value = b'\r\n\t'.join(values)
header = header + b': ' + value
self._output(header)
Modified: python/branches/py3k/Lib/test/test_httplib.py
==============================================================================
--- python/branches/py3k/Lib/test/test_httplib.py (original)
+++ python/branches/py3k/Lib/test/test_httplib.py Sun Oct 3 20:22:42 2010
@@ -90,6 +90,15 @@
conn.request('POST', '/', body, headers)
self.assertEqual(conn._buffer.count[header.lower()], 1)
+ def test_putheader(self):
+ conn = client.HTTPConnection('example.com')
+ conn.sock = FakeSocket(None)
+ conn.putrequest('GET','/')
+ conn.putheader('Content-length', 42)
+ print(conn._buffer)
+ self.assertTrue(b'Content-length: 42' in conn._buffer)
+
+
class BasicTest(TestCase):
def test_status_lines(self):
# Test HTTP status lines
More information about the Python-checkins
mailing list