summaryrefslogtreecommitdiffstats
path: root/Lib/gzip.py
diff options
context:
space:
mode:
authorNadeem Vawda <nadeem.vawda@gmail.com>2012-02-11 22:06:02 (GMT)
committerNadeem Vawda <nadeem.vawda@gmail.com>2012-02-11 22:06:02 (GMT)
commitbe66af424b7050be782ec2ea3458cac421658172 (patch)
tree5a2bc909ea6f5b36f17874a96d5533c5532fc52a /Lib/gzip.py
parentd1a107132cf8a500478885fef282a1f945b9a981 (diff)
downloadcpython-be66af424b7050be782ec2ea3458cac421658172.zip
cpython-be66af424b7050be782ec2ea3458cac421658172.tar.gz
cpython-be66af424b7050be782ec2ea3458cac421658172.tar.bz2
Clean up GzipFile mode string handling code.
Diffstat (limited to 'Lib/gzip.py')
-rw-r--r--Lib/gzip.py11
1 files changed, 5 insertions, 6 deletions
diff --git a/Lib/gzip.py b/Lib/gzip.py
index a5bfb85..85c3e15 100644
--- a/Lib/gzip.py
+++ b/Lib/gzip.py
@@ -141,7 +141,7 @@ class GzipFile(io.BufferedIOBase):
"""
if mode and ('t' in mode or 'U' in mode):
- raise IOError("Mode " + mode + " not supported")
+ raise ValueError("Invalid mode: {!r}".format(mode))
if mode and 'b' not in mode:
mode += 'b'
if fileobj is None:
@@ -152,10 +152,9 @@ class GzipFile(io.BufferedIOBase):
else:
filename = ''
if mode is None:
- if hasattr(fileobj, 'mode'): mode = fileobj.mode
- else: mode = 'rb'
+ mode = getattr(fileobj, 'mode', 'rb')
- if mode[0:1] == 'r':
+ if mode.startswith('r'):
self.mode = READ
# Set flag indicating start of a new member
self._new_member = True
@@ -170,7 +169,7 @@ class GzipFile(io.BufferedIOBase):
self.min_readsize = 100
fileobj = _PaddedFile(fileobj)
- elif mode[0:1] == 'w' or mode[0:1] == 'a':
+ elif mode.startswith(('w', 'a')):
self.mode = WRITE
self._init_write(filename)
self.compress = zlib.compressobj(compresslevel,
@@ -179,7 +178,7 @@ class GzipFile(io.BufferedIOBase):
zlib.DEF_MEM_LEVEL,
0)
else:
- raise IOError("Mode " + mode + " not supported")
+ raise ValueError("Invalid mode: {!r}".format(mode))
self.fileobj = fileobj
self.offset = 0