From 065f0c8a06e20c0b4f8c500c237cbafa7af7bd18 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20v=2E=20L=C3=B6wis?= Date: Sun, 12 Nov 2006 10:41:39 +0000 Subject: [PATCH] Patch #1355023: support whence argument for GzipFile.seek. --- Lib/gzip.py | 7 ++++++- Lib/test/test_gzip.py | 11 +++++++++++ Misc/NEWS | 2 ++ 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/Lib/gzip.py b/Lib/gzip.py index 0bf29e86bb5..c37d5a18c27 100644 --- a/Lib/gzip.py +++ b/Lib/gzip.py @@ -371,7 +371,12 @@ class GzipFile: 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 0f8e03e0a45..9989a92b70a 100644 --- a/Lib/test/test_gzip.py +++ b/Lib/test/test_gzip.py @@ -128,6 +128,17 @@ class TestGzip(unittest.TestCase): 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') diff --git a/Misc/NEWS b/Misc/NEWS index 3062bd528a4..39b698515a9 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -96,6 +96,8 @@ Core and builtins Library ------- +- Patch #1355023: support whence argument for GzipFile.seek. + - Patch #1065257: Support passing open files as body in HTTPConnection.request().