summaryrefslogtreecommitdiffstats
path: root/Lib/gzip.py
diff options
context:
space:
mode:
authorMartin v. Löwis <martin@v.loewis.de>2002-03-11 06:46:52 (GMT)
committerMartin v. Löwis <martin@v.loewis.de>2002-03-11 06:46:52 (GMT)
commitdb044899539e3ae047dcab87229013b8abb11a1f (patch)
tree0aeb959da9045bc18d67cbb9194ca6426197611e /Lib/gzip.py
parentc7f45412609e69be909591c3397a684571655e04 (diff)
downloadcpython-db044899539e3ae047dcab87229013b8abb11a1f.zip
cpython-db044899539e3ae047dcab87229013b8abb11a1f.tar.gz
cpython-db044899539e3ae047dcab87229013b8abb11a1f.tar.bz2
Patch #443899: Check modes on files before performing operations.
Use IOErrors where file objects use them.
Diffstat (limited to 'Lib/gzip.py')
-rw-r--r--Lib/gzip.py10
1 files changed, 9 insertions, 1 deletions
diff --git a/Lib/gzip.py b/Lib/gzip.py
index 7f56153..74c0d26 100644
--- a/Lib/gzip.py
+++ b/Lib/gzip.py
@@ -61,7 +61,7 @@ class GzipFile:
zlib.DEF_MEM_LEVEL,
0)
else:
- raise ValueError, "Mode " + mode + " not supported"
+ raise IOError, "Mode " + mode + " not supported"
self.fileobj = fileobj
self.offset = 0
@@ -133,6 +133,10 @@ class GzipFile:
def write(self,data):
+ if self.mode != WRITE:
+ import errno
+ raise IOError(errno.EBADF, "write() on read-only GzipFile object")
+
if self.fileobj is None:
raise ValueError, "write() on closed GzipFile object"
if len(data) > 0:
@@ -142,6 +146,10 @@ class GzipFile:
self.offset += len(data)
def read(self, size=-1):
+ if self.mode != READ:
+ import errno
+ raise IOError(errno.EBADF, "write() on read-only GzipFile object")
+
if self.extrasize <= 0 and self.fileobj is None:
return ''