Kaydet (Commit) 30d94b7a authored tarafından Nadeem Vawda's avatar Nadeem Vawda

Issue #13989: Document that GzipFile does not support text mode.

Also, give a more helpful error message when opened with an invalid mode string.
üst efe7c9d4
...@@ -44,9 +44,11 @@ The module defines the following items: ...@@ -44,9 +44,11 @@ The module defines the following items:
The *mode* argument can be any of ``'r'``, ``'rb'``, ``'a'``, ``'ab'``, ``'w'``, 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 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'``. If is the mode of *fileobj* if discernible; otherwise, the default is ``'rb'``.
not given, the 'b' flag will be added to the mode to ensure the file is opened
in binary mode for cross-platform portability. Note that the file is always opened in binary mode; text mode is not
supported. If you need to read a compressed file in text mode, wrap your
:class:`GzipFile` with an :class:`io.TextIOWrapper`.
The *compresslevel* argument is an integer from ``1`` to ``9`` controlling the The *compresslevel* argument is an integer from ``1`` to ``9`` controlling the
level of compression; ``1`` is fastest and produces the least compression, and level of compression; ``1`` is fastest and produces the least compression, and
......
...@@ -105,6 +105,9 @@ class GzipFile(io.BufferedIOBase): ...@@ -105,6 +105,9 @@ class GzipFile(io.BufferedIOBase):
"""The GzipFile class simulates most of the methods of a file object with """The GzipFile class simulates most of the methods of a file object with
the exception of the readinto() and truncate() methods. 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 myfileobj = None
...@@ -131,8 +134,8 @@ class GzipFile(io.BufferedIOBase): ...@@ -131,8 +134,8 @@ class GzipFile(io.BufferedIOBase):
The mode argument can be any of 'r', 'rb', 'a', 'ab', 'w', or 'wb', 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 depending on whether the file will be read or written. The default
is the mode of fileobj if discernible; otherwise, the default is 'rb'. 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 A mode of 'r' is equivalent to one of 'rb', and similarly for 'w' and
for cross-platform portability. 'wb', and 'a' and 'ab'.
The compresslevel argument is an integer from 1 to 9 controlling the The compresslevel argument is an integer from 1 to 9 controlling the
level of compression; 1 is fastest and produces the least compression, level of compression; 1 is fastest and produces the least compression,
...@@ -149,8 +152,8 @@ class GzipFile(io.BufferedIOBase): ...@@ -149,8 +152,8 @@ class GzipFile(io.BufferedIOBase):
""" """
# guarantee the file is opened in binary mode on platforms if mode and ('t' in mode or 'U' in mode):
# that care about that sort of thing raise IOError("Mode " + mode + " not supported")
if mode and 'b' not in mode: if mode and 'b' not in mode:
mode += 'b' mode += 'b'
if fileobj is None: if fileobj is None:
......
...@@ -113,6 +113,9 @@ Core and Builtins ...@@ -113,6 +113,9 @@ Core and Builtins
Library Library
------- -------
- Issue #13989: Document that GzipFile does not support text mode, and give a
more helpful error message when opened with an invalid mode string.
- Issue #13590: On OS X 10.7 and 10.6 with Xcode 4.2, building - Issue #13590: On OS X 10.7 and 10.6 with Xcode 4.2, building
Distutils-based packages with C extension modules may fail because Distutils-based packages with C extension modules may fail because
Apple has removed gcc-4.2, the version used to build python.org Apple has removed gcc-4.2, the version used to build python.org
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment