diff options
author | Nadeem Vawda <nadeem.vawda@gmail.com> | 2012-02-11 21:54:51 (GMT) |
---|---|---|
committer | Nadeem Vawda <nadeem.vawda@gmail.com> | 2012-02-11 21:54:51 (GMT) |
commit | d1a107132cf8a500478885fef282a1f945b9a981 (patch) | |
tree | c2d5e4d655484f17788f7c0a94acdf1d545e1e02 /Lib/gzip.py | |
parent | f4bdf4e478adc3f7c0ec54e60bb3359f51058722 (diff) | |
parent | 30d94b7aea69440605cc7d65e06ac374c25c74c1 (diff) | |
download | cpython-d1a107132cf8a500478885fef282a1f945b9a981.zip cpython-d1a107132cf8a500478885fef282a1f945b9a981.tar.gz cpython-d1a107132cf8a500478885fef282a1f945b9a981.tar.bz2 |
Merge: #13989: Document that GzipFile does not support text mode.
Diffstat (limited to 'Lib/gzip.py')
-rw-r--r-- | Lib/gzip.py | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/Lib/gzip.py b/Lib/gzip.py index 93dda4e..a5bfb85 100644 --- a/Lib/gzip.py +++ b/Lib/gzip.py @@ -93,6 +93,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 @@ -119,8 +122,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, @@ -137,8 +140,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: |