summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin v. Löwis <martin@v.loewis.de>2006-11-12 10:41:39 +0000
committerMartin v. Löwis <martin@v.loewis.de>2006-11-12 10:41:39 +0000
commit065f0c8a06e20c0b4f8c500c237cbafa7af7bd18 (patch)
tree65cb2e35ed1a4cee4c34e978aeb5053cc0fe0099
parent040a927cd14e799454b246dd1f56fd7f4fdff03a (diff)
downloadcpython-git-065f0c8a06e20c0b4f8c500c237cbafa7af7bd18.tar.gz
Patch #1355023: support whence argument for GzipFile.seek.
-rw-r--r--Lib/gzip.py7
-rw-r--r--Lib/test/test_gzip.py11
-rw-r--r--Misc/NEWS2
3 files changed, 19 insertions, 1 deletions
diff --git a/Lib/gzip.py b/Lib/gzip.py
index 0bf29e86bb..c37d5a18c2 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 0f8e03e0a4..9989a92b70 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 3062bd528a..39b698515a 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().