summaryrefslogtreecommitdiffstats
path: root/Lib/http
diff options
context:
space:
mode:
authorAntoine Pitrou <solipsis@pitrou.net>2009-02-11 00:39:14 (GMT)
committerAntoine Pitrou <solipsis@pitrou.net>2009-02-11 00:39:14 (GMT)
commitb353c12a9caa20e90466af6a8f17a227b72e4f23 (patch)
tree324c9dde570196bd47044f262e7387aef652919a /Lib/http
parent651453ace09e6677d8fea66d3cbbf8614b109f16 (diff)
downloadcpython-b353c12a9caa20e90466af6a8f17a227b72e4f23.zip
cpython-b353c12a9caa20e90466af6a8f17a227b72e4f23.tar.gz
cpython-b353c12a9caa20e90466af6a8f17a227b72e4f23.tar.bz2
Issue #4631: Fix urlopen() result when an HTTP response uses chunked encoding.
Diffstat (limited to 'Lib/http')
-rw-r--r--Lib/http/client.py12
1 files changed, 9 insertions, 3 deletions
diff --git a/Lib/http/client.py b/Lib/http/client.py
index f816d58..14a6c35 100644
--- a/Lib/http/client.py
+++ b/Lib/http/client.py
@@ -249,7 +249,7 @@ def parse_headers(fp):
return email.parser.Parser(_class=HTTPMessage).parsestr(hstring)
-class HTTPResponse:
+class HTTPResponse(io.RawIOBase):
# strict: If true, raise BadStatusLine if the status line can't be
# parsed as a valid HTTP/1.0 or 1.1 status line. By default it is
@@ -471,8 +471,6 @@ class HTTPResponse:
# called, meaning self.isclosed() is meaningful.
return self.fp is None
- # XXX It would be nice to have readline and __iter__ for this, too.
-
def read(self, amt=None):
if self.fp is None:
return b""
@@ -585,6 +583,9 @@ class HTTPResponse:
amt -= len(chunk)
return b"".join(s)
+ def fileno(self):
+ return self.fp.fileno()
+
def getheader(self, name, default=None):
if self.msg is None:
raise ResponseNotReady()
@@ -596,6 +597,11 @@ class HTTPResponse:
raise ResponseNotReady()
return list(self.msg.items())
+ # We override IOBase.__iter__ so that it doesn't check for closed-ness
+
+ def __iter__(self):
+ return self
+
class HTTPConnection: