[Python-checkins] cpython: use io.SEEK_* constants instead of os.SEEK_* where an IO stream is seeked,

eli.bendersky python-checkins at python.org
Tue Jan 3 05:26:19 CET 2012


http://hg.python.org/cpython/rev/120a79b8bb11
changeset:   74241:120a79b8bb11
user:        Eli Bendersky <eliben at gmail.com>
date:        Tue Jan 03 06:26:13 2012 +0200
summary:
  use io.SEEK_* constants instead of os.SEEK_* where an IO stream is seeked, leaving the os.SEEK_* constants only for os.lseek, as documented

files:
  Lib/tarfile.py          |  9 +++++----
  Lib/test/test_fileio.py |  5 +++--
  2 files changed, 8 insertions(+), 6 deletions(-)


diff --git a/Lib/tarfile.py b/Lib/tarfile.py
--- a/Lib/tarfile.py
+++ b/Lib/tarfile.py
@@ -40,6 +40,7 @@
 #---------
 import sys
 import os
+import io
 import shutil
 import stat
 import time
@@ -833,20 +834,20 @@
 
         return self.position
 
-    def seek(self, pos, whence=os.SEEK_SET):
+    def seek(self, pos, whence=io.SEEK_SET):
         """Seek to a position in the file.
         """
         if self.closed:
             raise ValueError("I/O operation on closed file")
 
-        if whence == os.SEEK_SET:
+        if whence == io.SEEK_SET:
             self.position = min(max(pos, 0), self.size)
-        elif whence == os.SEEK_CUR:
+        elif whence == io.SEEK_CUR:
             if pos < 0:
                 self.position = max(self.position + pos, 0)
             else:
                 self.position = min(self.position + pos, self.size)
-        elif whence == os.SEEK_END:
+        elif whence == io.SEEK_END:
             self.position = max(min(self.size + pos, self.size), 0)
         else:
             raise ValueError("Invalid argument")
diff --git a/Lib/test/test_fileio.py b/Lib/test/test_fileio.py
--- a/Lib/test/test_fileio.py
+++ b/Lib/test/test_fileio.py
@@ -2,6 +2,7 @@
 
 import sys
 import os
+import io
 import errno
 import unittest
 from array import array
@@ -334,10 +335,10 @@
         self.assertEqual(f.tell(), 10)
         f.truncate(5)
         self.assertEqual(f.tell(), 10)
-        self.assertEqual(f.seek(0, os.SEEK_END), 5)
+        self.assertEqual(f.seek(0, io.SEEK_END), 5)
         f.truncate(15)
         self.assertEqual(f.tell(), 5)
-        self.assertEqual(f.seek(0, os.SEEK_END), 15)
+        self.assertEqual(f.seek(0, io.SEEK_END), 15)
         f.close()
 
     def testTruncateOnWindows(self):

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list