summaryrefslogtreecommitdiff
path: root/Lib/gzip.py
diff options
context:
space:
mode:
authorNadeem Vawda <nadeem.vawda@gmail.com>2013-10-19 00:11:13 +0200
committerNadeem Vawda <nadeem.vawda@gmail.com>2013-10-19 00:11:13 +0200
commitee1be99e050db5ec2db534a2a28beb12ccf159de (patch)
tree6650c81d603e88bc0f2ae6c70b8688a204374778 /Lib/gzip.py
parent8a9e99cffcb579c208ccf92454be931e8a26dc39 (diff)
downloadcpython-git-ee1be99e050db5ec2db534a2a28beb12ccf159de.tar.gz
Issue #19222: Add support for the 'x' mode to the gzip module.
Original patch by Tim Heaney.
Diffstat (limited to 'Lib/gzip.py')
-rw-r--r--Lib/gzip.py14
1 files changed, 7 insertions, 7 deletions
diff --git a/Lib/gzip.py b/Lib/gzip.py
index b073a66bf1..8d21fe4bc2 100644
--- a/Lib/gzip.py
+++ b/Lib/gzip.py
@@ -23,9 +23,9 @@ def open(filename, mode="rb", compresslevel=9,
The filename argument can be an actual filename (a str or bytes object), or
an existing file object to read from or write to.
- The mode argument can be "r", "rb", "w", "wb", "a" or "ab" for binary mode,
- or "rt", "wt" or "at" for text mode. The default mode is "rb", and the
- default compresslevel is 9.
+ The mode argument can be "r", "rb", "w", "wb", "x", "xb", "a" or "ab" for
+ binary mode, or "rt", "wt", "xt" or "at" for text mode. The default mode is
+ "rb", and the default compresslevel is 9.
For binary mode, this function is equivalent to the GzipFile constructor:
GzipFile(filename, mode, compresslevel). In this case, the encoding, errors
@@ -151,11 +151,11 @@ class GzipFile(io.BufferedIOBase):
fileobj, if discernible; otherwise, it defaults to the empty string,
and in this case the original filename is not included in the header.
- 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
+ The mode argument can be any of 'r', 'rb', 'a', 'ab', 'w', 'wb', 'x', or
+ 'xb' depending on whether the file will be read or written. The default
is the mode of fileobj if discernible; otherwise, the default is 'rb'.
A mode of 'r' is equivalent to one of 'rb', and similarly for 'w' and
- 'wb', and 'a' and 'ab'.
+ 'wb', 'a' and 'ab', and 'x' and 'xb'.
The compresslevel argument is an integer from 0 to 9 controlling the
level of compression; 1 is fastest and produces the least compression,
@@ -201,7 +201,7 @@ class GzipFile(io.BufferedIOBase):
self.min_readsize = 100
fileobj = _PaddedFile(fileobj)
- elif mode.startswith(('w', 'a')):
+ elif mode.startswith(('w', 'a', 'x')):
self.mode = WRITE
self._init_write(filename)
self.compress = zlib.compressobj(compresslevel,