MCPcopy Index your code
hub / github.com/python/cpython / __init__

Method __init__

Lib/lzma.py:49–132  ·  view source on GitHub ↗

Open an LZMA-compressed file in binary mode. filename can be either an actual file name (given as a str, bytes, or PathLike object), in which case the named file is opened, or it can be an existing file object to read from or write to. mode can be "r" for re

(self, filename=None, mode="r", *,
                 format=None, check=-1, preset=None, filters=None)

Source from the content-addressed store, hash-verified

47 """
48
49 def __init__(self, filename=None, mode="r", *,
50 format=None, check=-1, preset=None, filters=None):
51 """Open an LZMA-compressed file in binary mode.
52
53 filename can be either an actual file name (given as a str,
54 bytes, or PathLike object), in which case the named file is
55 opened, or it can be an existing file object to read from or
56 write to.
57
58 mode can be "r" for reading (default), "w" for (over)writing,
59 "x" for creating exclusively, or "a" for appending. These can
60 equivalently be given as "rb", "wb", "xb" and "ab" respectively.
61
62 format specifies the container format to use for the file.
63 If mode is "r", this defaults to FORMAT_AUTO. Otherwise, the
64 default is FORMAT_XZ.
65
66 check specifies the integrity check to use. This argument can
67 only be used when opening a file for writing. For FORMAT_XZ,
68 the default is CHECK_CRC64. FORMAT_ALONE and FORMAT_RAW do not
69 support integrity checks - for these formats, check must be
70 omitted, or be CHECK_NONE.
71
72 When opening a file for reading, the *preset* argument is not
73 meaningful, and should be omitted. The *filters* argument should
74 also be omitted, except when format is FORMAT_RAW (in which case
75 it is required).
76
77 When opening a file for writing, the settings used by the
78 compressor can be specified either as a preset compression
79 level (with the *preset* argument), or in detail as a custom
80 filter chain (with the *filters* argument). For FORMAT_XZ and
81 FORMAT_ALONE, the default is to use the PRESET_DEFAULT preset
82 level. For FORMAT_RAW, the caller must always specify a filter
83 chain; the raw compressor does not support preset compression
84 levels.
85
86 preset (if provided) should be an integer in the range 0-9,
87 optionally OR-ed with the constant PRESET_EXTREME.
88
89 filters (if provided) should be a sequence of dicts. Each dict
90 should have an entry for "id" indicating ID of the filter, plus
91 additional entries for options to the filter.
92 """
93 self._fp = None
94 self._closefp = False
95 self._mode = None
96
97 if mode in ("r", "rb"):
98 if check != -1:
99 raise ValueError("Cannot specify an integrity check "
100 "when opening a file for reading")
101 if preset is not None:
102 raise ValueError("Cannot specify a preset compression "
103 "level when opening a file for reading")
104 if format is None:
105 format = FORMAT_AUTO
106 mode_code = _MODE_READ

Callers

nothing calls this directly

Calls 3

LZMACompressorClass · 0.85
formatMethod · 0.45
openMethod · 0.45

Tested by

no test coverage detected