mirror of
https://github.com/python/cpython.git
synced 2025-09-14 04:37:29 +00:00
give httplib.IncompleteRead a more sane repr #4308
This commit is contained in:
parent
ce45a967c2
commit
7d49bba969
4 changed files with 34 additions and 2 deletions
|
@ -626,7 +626,7 @@ class HTTPResponse:
|
|||
while amt > 0:
|
||||
chunk = self.fp.read(min(amt, MAXAMOUNT))
|
||||
if not chunk:
|
||||
raise IncompleteRead(s)
|
||||
raise IncompleteRead(''.join(s), amt)
|
||||
s.append(chunk)
|
||||
amt -= len(chunk)
|
||||
return ''.join(s)
|
||||
|
@ -1161,9 +1161,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