mirror of https://github.com/python/cpython.git
Patch #443899: Check modes on files before performing operations.
Use IOErrors where file objects use them.
This commit is contained in:
parent
c7f4541260
commit
db04489953
10
Lib/gzip.py
10
Lib/gzip.py
|
@ -61,7 +61,7 @@ def __init__(self, filename=None, mode=None,
|
||||||
zlib.DEF_MEM_LEVEL,
|
zlib.DEF_MEM_LEVEL,
|
||||||
0)
|
0)
|
||||||
else:
|
else:
|
||||||
raise ValueError, "Mode " + mode + " not supported"
|
raise IOError, "Mode " + mode + " not supported"
|
||||||
|
|
||||||
self.fileobj = fileobj
|
self.fileobj = fileobj
|
||||||
self.offset = 0
|
self.offset = 0
|
||||||
|
@ -133,6 +133,10 @@ def _read_gzip_header(self):
|
||||||
|
|
||||||
|
|
||||||
def write(self,data):
|
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:
|
if self.fileobj is None:
|
||||||
raise ValueError, "write() on closed GzipFile object"
|
raise ValueError, "write() on closed GzipFile object"
|
||||||
if len(data) > 0:
|
if len(data) > 0:
|
||||||
|
@ -142,6 +146,10 @@ def write(self,data):
|
||||||
self.offset += len(data)
|
self.offset += len(data)
|
||||||
|
|
||||||
def read(self, size=-1):
|
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:
|
if self.extrasize <= 0 and self.fileobj is None:
|
||||||
return ''
|
return ''
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue