[pypy-svn] r34207 - in pypy/branch/refactor-file/pypy/rlib: . test

cfbolz at codespeak.net cfbolz at codespeak.net
Sun Nov 5 10:29:35 CET 2006


Author: cfbolz
Date: Sun Nov  5 10:29:33 2006
New Revision: 34207

Modified:
   pypy/branch/refactor-file/pypy/rlib/streamio.py
   pypy/branch/refactor-file/pypy/rlib/test/test_streamio.py
Log:
always supply the whence argument explicitely to seek


Modified: pypy/branch/refactor-file/pypy/rlib/streamio.py
==============================================================================
--- pypy/branch/refactor-file/pypy/rlib/streamio.py	(original)
+++ pypy/branch/refactor-file/pypy/rlib/streamio.py	Sun Nov  5 10:29:33 2006
@@ -158,7 +158,7 @@
     def tell(self):
         raise NotImplementedError
 
-    def seek(self, offset, whence=0):
+    def seek(self, offset, whence):
         raise NotImplementedError
 
     def readall(self):
@@ -214,7 +214,7 @@
     def __init__(self, fd):
         self.fd = fd
 
-    def seek(self, offset, whence=0):
+    def seek(self, offset, whence):
         os.lseek(self.fd, offset, whence)
 
     def tell(self):
@@ -267,7 +267,7 @@
     def tell(self):
         return self.pos
 
-    def seek(self, offset, whence=0):
+    def seek(self, offset, whence):
         if whence == 0:
             self.pos = max(0, offset)
         elif whence == 1:
@@ -403,7 +403,7 @@
     def flush_buffers(self):
         if self.lines or self.buf:
             try:
-                self.do_seek(self.tell())
+                self.do_seek(self.tell(), 0)
             except NotImplementedError:
                 pass
             else:
@@ -418,7 +418,7 @@
         assert bytes >= offset #, (locals(), self.__dict__)
         return bytes - offset
 
-    def seek(self, offset, whence=0):
+    def seek(self, offset, whence):
         # This may fail on the do_seek() or do_tell() call.
         # But it won't call either on a relative forward seek.
         # Nor on a seek to the very end.
@@ -818,7 +818,7 @@
                 break
         return ''.join(result)
 
-    def seek(self, offset, whence=0):
+    def seek(self, offset, whence):
         """Seeks based on knowledge that does not come from a tell()
            may go to the wrong place, since the number of
            characters seen may not match the number of characters

Modified: pypy/branch/refactor-file/pypy/rlib/test/test_streamio.py
==============================================================================
--- pypy/branch/refactor-file/pypy/rlib/test/test_streamio.py	(original)
+++ pypy/branch/refactor-file/pypy/rlib/test/test_streamio.py	Sun Nov  5 10:29:33 2006
@@ -349,7 +349,7 @@
     def test_seek(self):
         file = self.makeStream(tell=True, seek=True)
         end = len(file.readall())
-        file.seek(0)
+        file.seek(0, 0)
         cases = [(readto, seekto, whence) for readto in range(0, end+1)
                                           for seekto in range(0, end+1)
                                           for whence in [0, 1, 2]]
@@ -360,7 +360,7 @@
             all = file.readall()
             assert end == len(all)
             for readto, seekto, whence in cases:
-                file.seek(0)
+                file.seek(0, 0)
                 assert file.tell() == 0
                 head = file.read(readto)
                 assert head == all[:readto]
@@ -461,7 +461,7 @@
             base = TWriter()
             filter = streamio.BufferingOutputStream(base, 4)
             filter.write("x"*6)
-            filter.seek(3)
+            filter.seek(3, 0)
             filter.write("y"*2)
             filter.close()
             assert base.buf == "x"*3 + "y"*2 + "x"*1
@@ -472,7 +472,7 @@
         def f():
             base = TWriter()
             filter = streamio.BufferingOutputStream(base, 4)
-            filter.seek(3)
+            filter.seek(3, 0)
             filter.write("y"*2)
             filter.close()
             assert base.buf == "\0"*3 + "y"*2
@@ -537,7 +537,7 @@
         filter = streamio.BufferingOutputStream(base, 4)
         def f():
             filter.write("x"*6)
-            filter.seek(3)
+            filter.seek(3, 0)
             filter.write("y"*2)
             filter.close()
             assert base.buf == "x"*3 + "y"*2 + "x"*1
@@ -620,9 +620,9 @@
         file.write("Barf\n")
         file.writelines(["a\n", "b\n", "c\n"])
         assert file.tell() == len("BooHoo\nBarf\na\nb\nc\n")
-        file.seek(0)
+        file.seek(0, 0)
         assert file.read() == "BooHoo\nBarf\na\nb\nc\n"
-        file.seek(0)
+        file.seek(0, 0)
         assert file.readlines() == (
                          ["BooHoo\n", "Barf\n", "a\n", "b\n", "c\n"])
         assert file.tell() == len("BooHoo\nBarf\na\nb\nc\n")
@@ -663,7 +663,7 @@
         filter = streamio.BufferingInputStream(
             streamio.BufferingOutputStream(base, 4), 4)
         def f():
-            filter.seek(3)
+            filter.seek(3, 0)
             filter.write("y"*2)
             filter.close()
             assert base.buf == "\0"*3 + "y"*2
@@ -762,7 +762,7 @@
             all = sofar
             for i in range(len(pairs)):
                 sofar, pos = pairs[i]
-                filter.seek(pos)
+                filter.seek(pos, 0)
                 assert filter.tell() == pos
                 assert filter.tell() == pos
                 bufs = [sofar]
@@ -850,7 +850,7 @@
             base = TWriter()
             filter = streamio.TextOutputFilter(base, linesep="\n")
             filter.write("x"*100)
-            filter.seek(50)
+            filter.seek(50, 0)
             filter.write("y"*10)
             assert base.buf == "x"*50 + "y"*10 + "x"*40
         self.interpret(f, [])



More information about the Pypy-commit mailing list