Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(31123)

Unified Diff: Lib/http/client.py

Issue 16723: io.TextIOWrapper on urllib.request.urlopen terminates prematurely
Patch Set: Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | Lib/test/test_httplib.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
--- a/Lib/http/client.py Sat Jan 26 19:00:20 2013 +0100
+++ b/Lib/http/client.py Sat Jan 26 22:05:22 2013 +0200
@@ -332,7 +332,7 @@
# 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
@@ -454,22 +454,24 @@
# otherwise, assume it will close
return True
+ def _close_conn(self):
+ self.fp.close()
+ self.fp = None
+
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
@@ -490,7 +492,7 @@
return b""
if self._method == "HEAD":
- self.close()
+ self._close_conn()
return b""
if amt is not None:
@@ -509,7 +511,7 @@
else:
s = self._safe_read(self.length)
self.length = 0
- self.close() # we read everything
+ self._close_conn() # we read everything
return s
def readinto(self, b):
@@ -517,7 +519,7 @@
return 0
if self._method == "HEAD":
- self.close()
+ self._close_conn()
return 0
if self.chunked:
@@ -535,10 +537,10 @@
if self.length is not None:
self.length -= n
if not self.length:
- self.close()
+ self._close_conn()
else:
if not n:
- self.close()
+ self._close_conn()
return n
def _read_next_chunk_size(self):
@@ -554,7 +556,7 @@
except ValueError:
# close the connection as protocol synchronisation is
# probably lost
- self.close()
+ self._close_conn()
raise
def _read_and_discard_trailer(self):
@@ -592,7 +594,7 @@
self._read_and_discard_trailer()
# we read everything; close the "file"
- self.close()
+ self._close_conn()
return b''.join(value)
@@ -633,7 +635,7 @@
self._read_and_discard_trailer()
# we read everything; close the "file"
- self.close()
+ self._close_conn()
return total_bytes
« no previous file with comments | « no previous file | Lib/test/test_httplib.py » ('j') | no next file with comments »

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+