Commit 065f0c8a authored by Martin v. Löwis's avatar Martin v. Löwis

Patch #1355023: support whence argument for GzipFile.seek.

parent 040a927c
...@@ -371,7 +371,12 @@ class GzipFile: ...@@ -371,7 +371,12 @@ class GzipFile:
self.extrasize = 0 self.extrasize = 0
self.offset = 0 self.offset = 0
def seek(self, offset): def seek(self, offset, whence=0):
if whence:
if whence == 1:
offset = self.offset + offset
else:
raise ValueError('Seek from end not supported')
if self.mode == WRITE: if self.mode == WRITE:
if offset < self.offset: if offset < self.offset:
raise IOError('Negative seek in write mode') raise IOError('Negative seek in write mode')
......
...@@ -128,6 +128,17 @@ class TestGzip(unittest.TestCase): ...@@ -128,6 +128,17 @@ class TestGzip(unittest.TestCase):
f.seek(newpos) # positive seek f.seek(newpos) # positive seek
f.close() f.close()
def test_seek_whence(self):
self.test_write()
# Try seek(whence=1), read test
f = gzip.GzipFile(self.filename)
f.read(10)
f.seek(10, whence=1)
y = f.read(10)
f.close()
self.assertEquals(y, data1[20:30])
def test_seek_write(self): def test_seek_write(self):
# Try seek, write test # Try seek, write test
f = gzip.GzipFile(self.filename, 'w') f = gzip.GzipFile(self.filename, 'w')
......
...@@ -96,6 +96,8 @@ Core and builtins ...@@ -96,6 +96,8 @@ Core and builtins
Library Library
------- -------
- Patch #1355023: support whence argument for GzipFile.seek.
- Patch #1065257: Support passing open files as body in - Patch #1065257: Support passing open files as body in
HTTPConnection.request(). HTTPConnection.request().
......
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