summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Lib/httplib.py13
-rw-r--r--Lib/test/test_httplib.py19
-rw-r--r--Misc/ACKS1
-rw-r--r--Misc/NEWS3
4 files changed, 34 insertions, 2 deletions
diff --git a/Lib/httplib.py b/Lib/httplib.py
index 2830ad726d..20a92047bf 100644
--- a/Lib/httplib.py
+++ b/Lib/httplib.py
@@ -616,7 +616,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)
@@ -1130,9 +1130,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
diff --git a/Lib/test/test_httplib.py b/Lib/test/test_httplib.py
index c8c0648e51..54a2b0ea6d 100644
--- a/Lib/test/test_httplib.py
+++ b/Lib/test/test_httplib.py
@@ -185,6 +185,8 @@ class BasicTest(TestCase):
resp.read()
except httplib.IncompleteRead, i:
self.assertEquals(i.partial, 'hello world')
+ self.assertEqual(repr(i),'IncompleteRead(11 bytes read)')
+ self.assertEqual(str(i),'IncompleteRead(11 bytes read)')
else:
self.fail('IncompleteRead expected')
finally:
@@ -198,6 +200,23 @@ class BasicTest(TestCase):
self.assertEquals(resp.read(), 'Hello\r\n')
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):
def test_responses(self):
diff --git a/Misc/ACKS b/Misc/ACKS
index 72b18c9c51..a869119aa0 100644
--- a/Misc/ACKS
+++ b/Misc/ACKS
@@ -753,6 +753,7 @@ Dik Winter
Blake Winton
Jean-Claude Wippler
Lars Wirzenius
+Chris Withers
Stefan Witzel
David Wolever
Klaus-Juergen Wolf
diff --git a/Misc/NEWS b/Misc/NEWS
index 64e9dee0c8..6093fc275b 100644
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -89,6 +89,9 @@ Core and Builtins
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
import guess_extension`` was used.