diff options
author | Benjamin Peterson <benjamin@python.org> | 2009-03-02 22:41:42 (GMT) |
---|---|---|
committer | Benjamin Peterson <benjamin@python.org> | 2009-03-02 22:41:42 (GMT) |
commit | 7d49bba969a6ca490ade6aa908e350d3c05f76f4 (patch) | |
tree | f3c3dbd9573fda44d86f40f9c1b9ff9fa7707529 /Lib/httplib.py | |
parent | ce45a967c2d82a6b3112c5621993f5fec1dd5ea1 (diff) | |
download | cpython-7d49bba969a6ca490ade6aa908e350d3c05f76f4.zip cpython-7d49bba969a6ca490ade6aa908e350d3c05f76f4.tar.gz cpython-7d49bba969a6ca490ade6aa908e350d3c05f76f4.tar.bz2 |
give httplib.IncompleteRead a more sane repr #4308
Diffstat (limited to 'Lib/httplib.py')
-rw-r--r-- | Lib/httplib.py | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/Lib/httplib.py b/Lib/httplib.py index 85e49ab..2e749ea 100644 --- a/Lib/httplib.py +++ b/Lib/httplib.py @@ -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 |