summaryrefslogtreecommitdiffstats
path: root/Lib/io.py
diff options
context:
space:
mode:
authorAntoine Pitrou <solipsis@pitrou.net>2010-05-15 20:33:07 (GMT)
committerAntoine Pitrou <solipsis@pitrou.net>2010-05-15 20:33:07 (GMT)
commitc400610321dcd16bff1e45ecb72a51244d43fbac (patch)
tree07a476a4be7d7eacf4fd8d25bb4d3faa96cf9a0a /Lib/io.py
parent6f1cfc1c12ce2bad4241dae14860acba7d4b294b (diff)
downloadcpython-c400610321dcd16bff1e45ecb72a51244d43fbac.zip
cpython-c400610321dcd16bff1e45ecb72a51244d43fbac.tar.gz
cpython-c400610321dcd16bff1e45ecb72a51244d43fbac.tar.bz2
Issue #7640: In the new `io` module, fix relative seek() for buffered
readable streams when the internal buffer isn't empty. Patch by Pascal Chambon.
Diffstat (limited to 'Lib/io.py')
-rw-r--r--Lib/io.py4
1 files changed, 4 insertions, 0 deletions
diff --git a/Lib/io.py b/Lib/io.py
index 54de504..1458b47 100644
--- a/Lib/io.py
+++ b/Lib/io.py
@@ -1199,6 +1199,10 @@ class BufferedRandom(BufferedWriter, BufferedReader):
self.flush()
# First do the raw seek, then empty the read buffer, so that
# if the raw seek fails, we don't lose buffered data forever.
+ if self._read_buf and whence == 1:
+ # Undo read ahead.
+ with self._read_lock:
+ self.raw.seek(self._read_pos - len(self._read_buf), 1)
pos = self.raw.seek(pos, whence)
with self._read_lock:
self._reset_read_buf()