cpython: b7948aaca1dd (original) (raw)

Mercurial > cpython

changeset 86450:b7948aaca1dd

Issue #19201: Add support for the 'x' mode to the lzma module. Patch by Tim Heaney and Vajrasky Kok. [#19201]

Nadeem Vawda nadeem.vawda@gmail.com
date Sat, 19 Oct 2013 00:06:19 +0200
parents bea507fbcd81
children 5abc04e6579b
files Doc/library/lzma.rst Lib/lzma.py Lib/test/test_lzma.py Misc/ACKS Misc/NEWS
diffstat 5 files changed, 51 insertions(+), 13 deletions(-)[+] [-] Doc/library/lzma.rst 15 Lib/lzma.py 13 Lib/test/test_lzma.py 32 Misc/ACKS 1 Misc/NEWS 3

line wrap: on

line diff

--- a/Doc/library/lzma.rst +++ b/Doc/library/lzma.rst @@ -39,8 +39,8 @@ Reading and writing compressed files opened, or it can be an existing file object to read from or write to. The mode argument can be any of "r", "rb", "w", "wb",

+ .. class:: LZMAFile(filename=None, mode="r", *, format=None, check=-1, preset=None, filters=None) @@ -69,8 +72,9 @@ Reading and writing compressed files file will not be closed when the :class:LZMAFile is closed. The mode argument can be either "r" for reading (default), "w" for

+ Compressing and decompressing data in memory --------------------------------------------

--- a/Lib/lzma.py +++ b/Lib/lzma.py @@ -54,9 +54,9 @@ class LZMAFile(io.BufferedIOBase): bytes object), in which case the named file is opened, or it can be an existing file object to read from or write to.

format specifies the container format to use for the file. If mode is "r", this defaults to FORMAT_AUTO. Otherwise, the @@ -112,7 +112,7 @@ class LZMAFile(io.BufferedIOBase): self._decompressor = LZMADecompressor(**self._init_args) self._buffer = b"" self._buffer_offset = 0

@@ -426,8 +426,9 @@ def open(filename, mode="rb", *, object), in which case the named file is opened, or it can be an existing file object to read from or write to.

The format, check, preset and filters arguments specify the compression settings, as for LZMACompressor, LZMADecompressor and

--- a/Lib/test/test_lzma.py +++ b/Lib/test/test_lzma.py @@ -362,6 +362,8 @@ class FileTestCase(unittest.TestCase): pass with LZMAFile(BytesIO(), "w") as f: pass

@@ -389,13 +391,29 @@ class FileTestCase(unittest.TestCase): with LZMAFile(TESTFN, "ab"): pass

+ def test_init_bad_mode(self): with self.assertRaises(ValueError): LZMAFile(BytesIO(COMPRESSED_XZ), (3, "x")) with self.assertRaises(ValueError): LZMAFile(BytesIO(COMPRESSED_XZ), "") with self.assertRaises(ValueError):

@@ -1022,8 +1040,6 @@ class OpenTestCase(unittest.TestCase): with self.assertRaises(ValueError): lzma.open(TESTFN, "") with self.assertRaises(ValueError):

@@ -1072,6 +1088,16 @@ class OpenTestCase(unittest.TestCase): with lzma.open(bio, "rt", newline="\r") as f: self.assertEqual(f.readlines(), [text])

+ class MiscellaneousTestCase(unittest.TestCase):

--- a/Misc/ACKS +++ b/Misc/ACKS @@ -506,6 +506,7 @@ Janko Hauser Rycharde Hawkes Ben Hayden Jochen Hayek +Tim Heaney Henrik Heimbuerger Christian Heimes Thomas Heller

--- a/Misc/NEWS +++ b/Misc/NEWS @@ -54,6 +54,9 @@ Core and Builtins Library ------- +- Issue #19201: Add "x" mode (exclusive creation) in opening file to lzma