aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@haypocalc.com>2011-05-26 00:19:38 +0200
committerVictor Stinner <victor.stinner@haypocalc.com>2011-05-26 00:19:38 +0200
commitb57f108b03df332d276a224c92e32cee13a042f2 (patch)
tree954924ef9693e020c58d90999bdb548af8f45f9f /Lib/_pyio.py
parentIssue #12175: FileIO.readall() now only reads the file position and size once. (diff)
downloadcpython-b57f108b03df332d276a224c92e32cee13a042f2.tar.gz
cpython-b57f108b03df332d276a224c92e32cee13a042f2.tar.bz2
cpython-b57f108b03df332d276a224c92e32cee13a042f2.zip
Issue #12175: BufferedReader.read(-1) now calls raw.readall() if available.
Diffstat (limited to 'Lib/_pyio.py')
-rw-r--r--Lib/_pyio.py6
1 files changed, 6 insertions, 0 deletions
diff --git a/Lib/_pyio.py b/Lib/_pyio.py
index 74047bf475b..265edab1134 100644
--- a/Lib/_pyio.py
+++ b/Lib/_pyio.py
@@ -944,6 +944,12 @@ class BufferedReader(_BufferedIOMixin):
# Special case for when the number of bytes to read is unspecified.
if n is None or n == -1:
self._reset_read_buf()
+ if hasattr(self.raw, 'readall'):
+ chunk = self.raw.readall()
+ if chunk is None:
+ return buf[pos:] or None
+ else:
+ return buf[pos:] + chunk
chunks = [buf[pos:]] # Strip the consumed bytes.
current_size = 0
while True: