Patch #1355023: support whence argument for GzipFile.seek.
diff --git a/Lib/gzip.py b/Lib/gzip.py
index 0bf29e8..c37d5a1 100644
--- a/Lib/gzip.py
+++ b/Lib/gzip.py
@@ -371,7 +371,12 @@
self.extrasize = 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 offset < self.offset:
raise IOError('Negative seek in write mode')
diff --git a/Lib/test/test_gzip.py b/Lib/test/test_gzip.py
index 0f8e03e..9989a92 100644
--- a/Lib/test/test_gzip.py
+++ b/Lib/test/test_gzip.py
@@ -128,6 +128,17 @@
f.seek(newpos) # positive seek
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):
# Try seek, write test
f = gzip.GzipFile(self.filename, 'w')