From: Martin v. Löwis Date: Mon, 11 Mar 2002 06:46:52 +0000 (+0000) Subject: Patch #443899: Check modes on files before performing operations. X-Git-Tag: v2.3c1~6528 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=db044899539e3ae047dcab87229013b8abb11a1f;p=python Patch #443899: Check modes on files before performing operations. Use IOErrors where file objects use them. --- diff --git a/Lib/gzip.py b/Lib/gzip.py index 7f561532ad..74c0d26a06 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 ''