summaryrefslogtreecommitdiffstats
path: root/Lib/http
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2013-02-06 08:31:57 (GMT)
committerSerhiy Storchaka <storchaka@gmail.com>2013-02-06 08:31:57 (GMT)
commitb5b9c8cd402b8ab8d6cb00f157ac855b37a1e5c6 (patch)
treec7aa684b08583ff7093928d4a2a6b641013c5c64 /Lib/http
parentf581b372003de0ae604c14a1f1dc2e8c36ea277b (diff)
downloadcpython-b5b9c8cd402b8ab8d6cb00f157ac855b37a1e5c6.zip
cpython-b5b9c8cd402b8ab8d6cb00f157ac855b37a1e5c6.tar.gz
cpython-b5b9c8cd402b8ab8d6cb00f157ac855b37a1e5c6.tar.bz2
Issue #16723: httplib.HTTPResponse no longer marked closed when the connection
is automatically closed.
Diffstat (limited to 'Lib/http')
-rw-r--r--Lib/http/client.py34
1 files changed, 19 insertions, 15 deletions
diff --git a/Lib/http/client.py b/Lib/http/client.py
index 4574eed..5466d06 100644
--- a/Lib/http/client.py
+++ b/Lib/http/client.py
@@ -324,7 +324,7 @@ class HTTPResponse(io.RawIOBase):
# empty version will cause next test to fail.
version = ""
if not version.startswith("HTTP/"):
- self.close()
+ self._close_conn()
raise BadStatusLine(line)
# The status code is a three-digit number
@@ -446,22 +446,25 @@ class HTTPResponse(io.RawIOBase):
# otherwise, assume it will close
return True
+ def _close_conn(self):
+ fp = self.fp
+ self.fp = None
+ fp.close()
+
def close(self):
+ super().close() # set "closed" flag
if self.fp:
- self.fp.close()
- self.fp = None
+ self._close_conn()
# These implementations are for the benefit of io.BufferedReader.
# XXX This class should probably be revised to act more like
# the "raw stream" that BufferedReader expects.
- @property
- def closed(self):
- return self.isclosed()
-
def flush(self):
- self.fp.flush()
+ super().flush()
+ if self.fp:
+ self.fp.flush()
def readable(self):
return True
@@ -469,6 +472,7 @@ class HTTPResponse(io.RawIOBase):
# End of "raw stream" methods
def isclosed(self):
+ """True if the connection is closed."""
# NOTE: it is possible that we will not ever call self.close(). This
# case occurs when will_close is TRUE, length is None, and we
# read up to the last byte, but NOT past it.
@@ -482,7 +486,7 @@ class HTTPResponse(io.RawIOBase):
return b""
if self._method == "HEAD":
- self.close()
+ self._close_conn()
return b""
if self.chunked:
@@ -496,10 +500,10 @@ class HTTPResponse(io.RawIOBase):
try:
s = self._safe_read(self.length)
except IncompleteRead:
- self.close()
+ self._close_conn()
raise
self.length = 0
- self.close() # we read everything
+ self._close_conn() # we read everything
return s
if self.length is not None:
@@ -514,11 +518,11 @@ class HTTPResponse(io.RawIOBase):
if not s:
# Ideally, we would raise IncompleteRead if the content-length
# wasn't satisfied, but it might break compatibility.
- self.close()
+ self._close_conn()
elif self.length is not None:
self.length -= len(s)
if not self.length:
- self.close()
+ self._close_conn()
return s
@@ -539,7 +543,7 @@ class HTTPResponse(io.RawIOBase):
except ValueError:
# close the connection as protocol synchronisation is
# probably lost
- self.close()
+ self._close_conn()
raise IncompleteRead(b''.join(value))
if chunk_left == 0:
break
@@ -576,7 +580,7 @@ class HTTPResponse(io.RawIOBase):
break
# we read everything; close the "file"
- self.close()
+ self._close_conn()
return b''.join(value)