mirror of
https://github.com/python/cpython.git
synced 2025-08-17 23:31:09 +00:00
Merged revisions 70107 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk ........ r70107 | benjamin.peterson | 2009-03-02 16:41:42 -0600 (Mon, 02 Mar 2009) | 1 line give httplib.IncompleteRead a more sane repr #4308 ........
This commit is contained in:
parent
43c0464d84
commit
a97bed9572
4 changed files with 34 additions and 2 deletions
|
@ -616,7 +616,7 @@ class HTTPResponse:
|
||||||
while amt > 0:
|
while amt > 0:
|
||||||
chunk = self.fp.read(min(amt, MAXAMOUNT))
|
chunk = self.fp.read(min(amt, MAXAMOUNT))
|
||||||
if not chunk:
|
if not chunk:
|
||||||
raise IncompleteRead(s)
|
raise IncompleteRead(''.join(s), amt)
|
||||||
s.append(chunk)
|
s.append(chunk)
|
||||||
amt -= len(chunk)
|
amt -= len(chunk)
|
||||||
return ''.join(s)
|
return ''.join(s)
|
||||||
|
@ -1130,9 +1130,18 @@ class UnimplementedFileMode(HTTPException):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
class IncompleteRead(HTTPException):
|
class IncompleteRead(HTTPException):
|
||||||
def __init__(self, partial):
|
def __init__(self, partial, expected=None):
|
||||||
self.args = partial,
|
self.args = partial,
|
||||||
self.partial = partial
|
self.partial = partial
|
||||||
|
self.expected = expected
|
||||||
|
def __repr__(self):
|
||||||
|
if self.expected is not None:
|
||||||
|
e = ', %i more expected' % self.expected
|
||||||
|
else:
|
||||||
|
e = ''
|
||||||
|
return 'IncompleteRead(%i bytes read%s)' % (len(self.partial), e)
|
||||||
|
def __str__(self):
|
||||||
|
return repr(self)
|
||||||
|
|
||||||
class ImproperConnectionState(HTTPException):
|
class ImproperConnectionState(HTTPException):
|
||||||
pass
|
pass
|
||||||
|
|
|
@ -185,6 +185,8 @@ class BasicTest(TestCase):
|
||||||
resp.read()
|
resp.read()
|
||||||
except httplib.IncompleteRead, i:
|
except httplib.IncompleteRead, i:
|
||||||
self.assertEquals(i.partial, 'hello world')
|
self.assertEquals(i.partial, 'hello world')
|
||||||
|
self.assertEqual(repr(i),'IncompleteRead(11 bytes read)')
|
||||||
|
self.assertEqual(str(i),'IncompleteRead(11 bytes read)')
|
||||||
else:
|
else:
|
||||||
self.fail('IncompleteRead expected')
|
self.fail('IncompleteRead expected')
|
||||||
finally:
|
finally:
|
||||||
|
@ -198,6 +200,23 @@ class BasicTest(TestCase):
|
||||||
self.assertEquals(resp.read(), 'Hello\r\n')
|
self.assertEquals(resp.read(), 'Hello\r\n')
|
||||||
resp.close()
|
resp.close()
|
||||||
|
|
||||||
|
def test_incomplete_read(self):
|
||||||
|
sock = FakeSocket('HTTP/1.1 200 OK\r\nContent-Length: 10\r\n\r\nHello\r\n')
|
||||||
|
resp = httplib.HTTPResponse(sock, method="GET")
|
||||||
|
resp.begin()
|
||||||
|
try:
|
||||||
|
resp.read()
|
||||||
|
except httplib.IncompleteRead as i:
|
||||||
|
self.assertEquals(i.partial, 'Hello\r\n')
|
||||||
|
self.assertEqual(repr(i),
|
||||||
|
"IncompleteRead(7 bytes read, 3 more expected)")
|
||||||
|
self.assertEqual(str(i),
|
||||||
|
"IncompleteRead(7 bytes read, 3 more expected)")
|
||||||
|
else:
|
||||||
|
self.fail('IncompleteRead expected')
|
||||||
|
finally:
|
||||||
|
resp.close()
|
||||||
|
|
||||||
|
|
||||||
class OfflineTest(TestCase):
|
class OfflineTest(TestCase):
|
||||||
def test_responses(self):
|
def test_responses(self):
|
||||||
|
|
|
@ -753,6 +753,7 @@ Dik Winter
|
||||||
Blake Winton
|
Blake Winton
|
||||||
Jean-Claude Wippler
|
Jean-Claude Wippler
|
||||||
Lars Wirzenius
|
Lars Wirzenius
|
||||||
|
Chris Withers
|
||||||
Stefan Witzel
|
Stefan Witzel
|
||||||
David Wolever
|
David Wolever
|
||||||
Klaus-Juergen Wolf
|
Klaus-Juergen Wolf
|
||||||
|
|
|
@ -89,6 +89,9 @@ Core and Builtins
|
||||||
Library
|
Library
|
||||||
-------
|
-------
|
||||||
|
|
||||||
|
- Issue #4308: httplib.IncompleteRead's repr doesn't include all of the data all
|
||||||
|
ready received.
|
||||||
|
|
||||||
- Issue #5401: Fixed a performance problem in mimetypes when ``from mimetypes
|
- Issue #5401: Fixed a performance problem in mimetypes when ``from mimetypes
|
||||||
import guess_extension`` was used.
|
import guess_extension`` was used.
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue