Commit 8ca7bbb5 authored by Eli Bendersky's avatar Eli Bendersky

use io.SEEK_* constants instead of os.SEEK_* where an IO stream is seeked,...

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
parent fd569ea5
...@@ -40,6 +40,7 @@ __credits__ = "Gustavo Niemeyer, Niels Gust\u00e4bel, Richard Townsend." ...@@ -40,6 +40,7 @@ __credits__ = "Gustavo Niemeyer, Niels Gust\u00e4bel, Richard Townsend."
#--------- #---------
import sys import sys
import os import os
import io
import shutil import shutil
import stat import stat
import time import time
...@@ -833,20 +834,20 @@ class ExFileObject(object): ...@@ -833,20 +834,20 @@ class ExFileObject(object):
return self.position 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. """Seek to a position in the file.
""" """
if self.closed: if self.closed:
raise ValueError("I/O operation on closed file") 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) self.position = min(max(pos, 0), self.size)
elif whence == os.SEEK_CUR: elif whence == io.SEEK_CUR:
if pos < 0: if pos < 0:
self.position = max(self.position + pos, 0) self.position = max(self.position + pos, 0)
else: else:
self.position = min(self.position + pos, self.size) 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) self.position = max(min(self.size + pos, self.size), 0)
else: else:
raise ValueError("Invalid argument") raise ValueError("Invalid argument")
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
import sys import sys
import os import os
import io
import errno import errno
import unittest import unittest
from array import array from array import array
...@@ -334,10 +335,10 @@ class OtherFileTests(unittest.TestCase): ...@@ -334,10 +335,10 @@ class OtherFileTests(unittest.TestCase):
self.assertEqual(f.tell(), 10) self.assertEqual(f.tell(), 10)
f.truncate(5) f.truncate(5)
self.assertEqual(f.tell(), 10) 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) f.truncate(15)
self.assertEqual(f.tell(), 5) 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() f.close()
def testTruncateOnWindows(self): def testTruncateOnWindows(self):
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment