mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +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
a4f52b12d6
commit
6accb988a1
3 changed files with 31 additions and 2 deletions
|
@ -578,7 +578,7 @@ class HTTPResponse(io.RawIOBase):
|
|||
while amt > 0:
|
||||
chunk = self.fp.read(min(amt, MAXAMOUNT))
|
||||
if not chunk:
|
||||
raise IncompleteRead(s)
|
||||
raise IncompleteRead(b''.join(s), amt)
|
||||
s.append(chunk)
|
||||
amt -= len(chunk)
|
||||
return b"".join(s)
|
||||
|
@ -1009,9 +1009,18 @@ class UnimplementedFileMode(HTTPException):
|
|||
pass
|
||||
|
||||
class IncompleteRead(HTTPException):
|
||||
def __init__(self, partial):
|
||||
def __init__(self, partial, expected=None):
|
||||
self.args = 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):
|
||||
pass
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue