cpython: b512780c6589 (original) (raw)

Mercurial > cpython

changeset 104287:b512780c6589 3.6

Issue #28229: lzma module now supports pathlib [#28229]

Berker Peksag berker.peksag@gmail.com
date Tue, 04 Oct 2016 20:41:20 +0300
parents 3a7234d04fe9
children de398937653b 99c37fa72b66
files Doc/library/lzma.rst Lib/lzma.py Lib/test/test_lzma.py Misc/NEWS
diffstat 4 files changed, 47 insertions(+), 13 deletions(-)[+] [-] Doc/library/lzma.rst 18 Lib/lzma.py 18 Lib/test/test_lzma.py 22 Misc/NEWS 2

line wrap: on

line diff

--- a/Doc/library/lzma.rst +++ b/Doc/library/lzma.rst @@ -39,8 +39,9 @@ Reading and writing compressed files object`. The filename argument can be either an actual file name (given as a

+ .. class:: LZMAFile(filename=None, mode="r", *, format=None, check=-1, preset=None, filters=None) @@ -71,9 +75,10 @@ Reading and writing compressed files An :class:LZMAFile can wrap an already-open :term:file object, or operate directly on a named file. The filename argument specifies either the file

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

--- a/Lib/lzma.py +++ b/Lib/lzma.py @@ -23,6 +23,7 @@ container formats, as well as raw compre import builtins import io +import os from _lzma import * from _lzma import _encode_filter_properties, _decode_filter_properties import _compression @@ -49,9 +50,10 @@ class LZMAFile(_compression.BaseStream): format=None, check=-1, preset=None, filters=None): """Open an LZMA-compressed file in binary mode.

mode can be "r" for reading (default), "w" for (over)writing, "x" for creating exclusively, or "a" for appending. These can @@ -112,7 +114,7 @@ class LZMAFile(_compression.BaseStream): else: raise ValueError("Invalid mode: {!r}".format(mode))

@@ -122,7 +124,7 @@ class LZMAFile(_compression.BaseStream): self._fp = filename self._mode = mode_code else:

if self._mode == _MODE_READ: raw = _compression.DecompressReader(self._fp, LZMADecompressor, @@ -263,9 +265,9 @@ def open(filename, mode="rb", *, encoding=None, errors=None, newline=None): """Open an LZMA-compressed file in binary or text mode.

The mode argument can be "r", "rb" (default), "w", "wb", "x", "xb", "a", or "ab" for binary mode, or "rt", "wt", "xt", or "at" for text

--- a/Lib/test/test_lzma.py +++ b/Lib/test/test_lzma.py @@ -1,6 +1,7 @@ import _compression from io import BytesIO, UnsupportedOperation, DEFAULT_BUFFER_SIZE import os +import pathlib import pickle import random import unittest @@ -488,6 +489,16 @@ class FileTestCase(unittest.TestCase): with LZMAFile(BytesIO(), "a") as f: pass

+ def test_init_with_filename(self): with TempFile(TESTFN, COMPRESSED_XZ): with LZMAFile(TESTFN) as f: @@ -1180,6 +1191,17 @@ class OpenTestCase(unittest.TestCase): with lzma.open(TESTFN, "rb") as f: self.assertEqual(f.read(), INPUT * 2)

+ def test_bad_params(self): # Test invalid parameter combinations. with self.assertRaises(ValueError):

--- a/Misc/NEWS +++ b/Misc/NEWS @@ -50,6 +50,8 @@ Core and Builtins Library ------- +- Issue #28229: lzma module now supports pathlib. +