[Python-checkins] r70067 - python/branches/io-c/Lib/_pyio.py

benjamin.peterson python-checkins at python.org
Sat Feb 28 17:43:20 CET 2009


Author: benjamin.peterson
Date: Sat Feb 28 17:43:20 2009
New Revision: 70067

Log:
1. make sure to undo buffered read aheads in BufferedRandom.seek()
2. refill the buffer if have <= 0
3. fix the last failing test_io test!


Modified:
   python/branches/io-c/Lib/_pyio.py

Modified: python/branches/io-c/Lib/_pyio.py
==============================================================================
--- python/branches/io-c/Lib/_pyio.py	(original)
+++ python/branches/io-c/Lib/_pyio.py	Sat Feb 28 17:43:20 2009
@@ -916,7 +916,7 @@
     def _peek_unlocked(self, n=0):
         want = min(n, self.buffer_size)
         have = len(self._read_buf) - self._read_pos
-        if have < want:
+        if have < want or have <= 0:
             to_read = self.buffer_size - have
             current = self.raw.read(to_read)
             if current:
@@ -1130,6 +1130,10 @@
         if not (0 <= whence <= 2):
             raise ValueError("invalid whence")
         self.flush()
+        if self._read_buf:
+            # Undo read ahead.
+            with self._read_lock:
+                self.raw.seek(self._read_pos - len(self._read_buf), 1)
         # First do the raw seek, then empty the read buffer, so that
         # if the raw seek fails, we don't lose buffered data forever.
         pos = self.raw.seek(pos, whence)


More information about the Python-checkins mailing list