diff options
author | Nadeem Vawda <nadeem.vawda@gmail.com> | 2013-10-18 22:11:06 (GMT) |
---|---|---|
committer | Nadeem Vawda <nadeem.vawda@gmail.com> | 2013-10-18 22:11:06 (GMT) |
commit | 8a9e99cffcb579c208ccf92454be931e8a26dc39 (patch) | |
tree | 94d3e3b07c08dd9db8c6765c0693c6dc0e23fe09 /Lib/bz2.py | |
parent | 42ca98217ca544220fdf4d33875c811f342edc56 (diff) | |
download | cpython-8a9e99cffcb579c208ccf92454be931e8a26dc39.zip cpython-8a9e99cffcb579c208ccf92454be931e8a26dc39.tar.gz cpython-8a9e99cffcb579c208ccf92454be931e8a26dc39.tar.bz2 |
Issue #19223: Add support for the 'x' mode to the bz2 module.
Patch by Tim Heaney and Vajrasky Kok.
Diffstat (limited to 'Lib/bz2.py')
-rw-r--r-- | Lib/bz2.py | 16 |
1 files changed, 10 insertions, 6 deletions
@@ -49,12 +49,12 @@ class BZ2File(io.BufferedIOBase): which will be used to read or write the compressed data. mode can be 'r' for reading (default), 'w' for (over)writing, - or 'a' for appending. These can equivalently be given as 'rb', - 'wb', and 'ab'. + 'x' for creating exclusively, or 'a' for appending. These can + equivalently be given as 'rb', 'wb', 'xb', and 'ab'. buffering is ignored. Its use is deprecated. - If mode is 'w' or 'a', compresslevel can be a number between 1 + If mode is 'w', 'x' or 'a', compresslevel can be a number between 1 and 9 specifying the level of compression: 1 produces the least compression, and 9 (default) produces the most compression. @@ -87,6 +87,10 @@ class BZ2File(io.BufferedIOBase): mode = "wb" mode_code = _MODE_WRITE self._compressor = BZ2Compressor(compresslevel) + elif mode in ("x", "xb"): + mode = "xb" + mode_code = _MODE_WRITE + self._compressor = BZ2Compressor(compresslevel) elif mode in ("a", "ab"): mode = "ab" mode_code = _MODE_WRITE @@ -443,9 +447,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 BZ2File constructor: BZ2File(filename, mode, compresslevel). In this case, |