summaryrefslogtreecommitdiffstats
path: root/Lib/gzip.py
diff options
context:
space:
mode:
authorNadeem Vawda <nadeem.vawda@gmail.com>2012-02-11 21:45:10 (GMT)
committerNadeem Vawda <nadeem.vawda@gmail.com>2012-02-11 21:45:10 (GMT)
commit30d94b7aea69440605cc7d65e06ac374c25c74c1 (patch)
tree1f32bbd25dcd469fa0ee843e98a6eaa5bfebe616 /Lib/gzip.py
parentefe7c9d4d7afef1895c2da72f4a40d934a6f8fee (diff)
downloadcpython-30d94b7aea69440605cc7d65e06ac374c25c74c1.zip
cpython-30d94b7aea69440605cc7d65e06ac374c25c74c1.tar.gz
cpython-30d94b7aea69440605cc7d65e06ac374c25c74c1.tar.bz2
Issue #13989: Document that GzipFile does not support text mode.
Also, give a more helpful error message when opened with an invalid mode string.
Diffstat (limited to 'Lib/gzip.py')
-rw-r--r--Lib/gzip.py11
1 files changed, 7 insertions, 4 deletions
diff --git a/Lib/gzip.py b/Lib/gzip.py
index 4462187..1de23b6 100644
--- a/Lib/gzip.py
+++ b/Lib/gzip.py
@@ -105,6 +105,9 @@ class GzipFile(io.BufferedIOBase):
"""The GzipFile class simulates most of the methods of a file object with
the exception of the readinto() and truncate() methods.
+ This class only supports opening files in binary mode. If you need to open a
+ compressed file in text mode, wrap your GzipFile with an io.TextIOWrapper.
+
"""
myfileobj = None
@@ -131,8 +134,8 @@ class GzipFile(io.BufferedIOBase):
The mode argument can be any of 'r', 'rb', 'a', 'ab', 'w', or 'wb',
depending on whether the file will be read or written. The default
is the mode of fileobj if discernible; otherwise, the default is 'rb'.
- Be aware that only the 'rb', 'ab', and 'wb' values should be used
- for cross-platform portability.
+ A mode of 'r' is equivalent to one of 'rb', and similarly for 'w' and
+ 'wb', and 'a' and 'ab'.
The compresslevel argument is an integer from 1 to 9 controlling the
level of compression; 1 is fastest and produces the least compression,
@@ -149,8 +152,8 @@ class GzipFile(io.BufferedIOBase):
"""
- # guarantee the file is opened in binary mode on platforms
- # that care about that sort of thing
+ if mode and ('t' in mode or 'U' in mode):
+ raise IOError("Mode " + mode + " not supported")
if mode and 'b' not in mode:
mode += 'b'
if fileobj is None: