diff options
author | Christian Heimes <christian@cheimes.de> | 2007-11-08 18:04:45 (GMT) |
---|---|---|
committer | Christian Heimes <christian@cheimes.de> | 2007-11-08 18:04:45 (GMT) |
commit | 8e42a0a0e0358c2004c33e0c7415ca48874df991 (patch) | |
tree | 79d6df5b01ae1da021d2776d085186742dfd774a /Lib | |
parent | 8bd14fb398b1b89c82defdac6c5755c9ca86859b (diff) | |
download | cpython-8e42a0a0e0358c2004c33e0c7415ca48874df991.zip cpython-8e42a0a0e0358c2004c33e0c7415ca48874df991.tar.gz cpython-8e42a0a0e0358c2004c33e0c7415ca48874df991.tar.bz2 |
Fixed bug #1081: file.seek allows float arguments
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/io.py | 2 | ||||
-rw-r--r-- | Lib/test/test_io.py | 4 |
2 files changed, 6 insertions, 0 deletions
@@ -694,6 +694,8 @@ class BytesIO(BufferedIOBase): return n def seek(self, pos, whence=0): + if not isinstance(pos, int): + raise TypeError("an integer is required") if whence == 0: self._pos = max(0, pos) elif whence == 1: diff --git a/Lib/test/test_io.py b/Lib/test/test_io.py index 6091e89..dace642 100644 --- a/Lib/test/test_io.py +++ b/Lib/test/test_io.py @@ -95,6 +95,7 @@ class IOTest(unittest.TestCase): self.assertEqual(f.tell(), 13) self.assertEqual(f.truncate(12), 12) self.assertEqual(f.tell(), 13) + self.assertRaises(TypeError, f.seek, 0.0) def read_ops(self, f, buffered=False): data = f.read(5) @@ -116,6 +117,7 @@ class IOTest(unittest.TestCase): self.assertEqual(f.seek(-6, 1), 5) self.assertEqual(f.read(5), b" worl") self.assertEqual(f.tell(), 10) + self.assertRaises(TypeError, f.seek, 0.0) if buffered: f.seek(0) self.assertEqual(f.read(), b"hello world\n") @@ -296,6 +298,7 @@ class MemorySeekTestMixin: bytesIo.seek(3) self.assertEquals(buf[3:], bytesIo.read()) + self.assertRaises(TypeError, bytesIo.seek, 0.0) def testTell(self): buf = self.buftype("1234567890") @@ -481,6 +484,7 @@ class BufferedRandomTest(unittest.TestCase): rw.seek(2, 1) self.assertEquals(7, rw.tell()) self.assertEquals(b"fl", rw.read(11)) + self.assertRaises(TypeError, rw.seek, 0.0) class TextIOWrapperTest(unittest.TestCase): |