]> granicus.if.org Git - python/commitdiff
Merged revisions 70107 via svnmerge from
authorBenjamin Peterson <benjamin@python.org>
Mon, 2 Mar 2009 22:50:25 +0000 (22:50 +0000)
committerBenjamin Peterson <benjamin@python.org>
Mon, 2 Mar 2009 22:50:25 +0000 (22:50 +0000)
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
........

Lib/http/client.py
Lib/test/test_httplib.py
Misc/ACKS

index 14a6c35c6e5fc8219faaf25054b271eb542053be..b1b76c283b46a214efccd4fe8f4c0e01fc2d5f53 100644 (file)
@@ -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
index 099f803638bc2aa086a0dfad28f5d1400c92b564..a433474bc0e50a19660d976f40583cee1f2cdbff 100644 (file)
@@ -181,6 +181,8 @@ class BasicTest(TestCase):
                 resp.read()
             except httplib.IncompleteRead as i:
                 self.assertEquals(i.partial, b'hello world')
+                self.assertEqual(repr(i),'IncompleteRead(11 bytes read)')
+                self.assertEqual(str(i),'IncompleteRead(11 bytes read)')
             else:
                 self.fail('IncompleteRead expected')
             finally:
@@ -194,6 +196,23 @@ class BasicTest(TestCase):
         self.assertEquals(resp.read(), b'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, b'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):
index ca6500e1c2254b2b8e13a93abe37f6ac2eff8450..7084f21f2870e4bb77c0216f1995fa7b1991a075 100644 (file)
--- a/Misc/ACKS
+++ b/Misc/ACKS
@@ -767,6 +767,7 @@ Dik Winter
 Blake Winton
 Jean-Claude Wippler
 Lars Wirzenius
+Chris Withers
 Stefan Witzel
 David Wolever
 Klaus-Juergen Wolf