MCPcopy Create free account
hub / github.com/RT-Thread/env-windows / open

Function open

tools/python-3.11.9-amd64/Lib/lzma.py:271–316  ·  view source on GitHub ↗

Open an LZMA-compressed file in binary or text 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. The mode argument can be "r", "r

(filename, mode="rb", *,
         format=None, check=-1, preset=None, filters=None,
         encoding=None, errors=None, newline=None)

Source from the content-addressed store, hash-verified

269
270
271def open(filename, mode="rb", *,
272 format=None, check=-1, preset=None, filters=None,
273 encoding=None, errors=None, newline=None):
274 """Open an LZMA-compressed file in binary or text mode.
275
276 filename can be either an actual file name (given as a str, bytes,
277 or PathLike object), in which case the named file is opened, or it
278 can be an existing file object to read from or write to.
279
280 The mode argument can be "r", "rb" (default), "w", "wb", "x", "xb",
281 "a", or "ab" for binary mode, or "rt", "wt", "xt", or "at" for text
282 mode.
283
284 The format, check, preset and filters arguments specify the
285 compression settings, as for LZMACompressor, LZMADecompressor and
286 LZMAFile.
287
288 For binary mode, this function is equivalent to the LZMAFile
289 constructor: LZMAFile(filename, mode, ...). In this case, the
290 encoding, errors and newline arguments must not be provided.
291
292 For text mode, an LZMAFile object is created, and wrapped in an
293 io.TextIOWrapper instance with the specified encoding, error
294 handling behavior, and line ending(s).
295
296 """
297 if "t" in mode:
298 if "b" in mode:
299 raise ValueError("Invalid mode: %r" % (mode,))
300 else:
301 if encoding is not None:
302 raise ValueError("Argument 'encoding' not supported in binary mode")
303 if errors is not None:
304 raise ValueError("Argument 'errors' not supported in binary mode")
305 if newline is not None:
306 raise ValueError("Argument 'newline' not supported in binary mode")
307
308 lz_mode = mode.replace("t", "")
309 binary_file = LZMAFile(filename, lz_mode, format=format, check=check,
310 preset=preset, filters=filters)
311
312 if "t" in mode:
313 encoding = io.text_encoding(encoding)
314 return io.TextIOWrapper(binary_file, encoding, errors, newline)
315 else:
316 return binary_file
317
318
319def compress(data, format=FORMAT_XZ, check=-1, preset=None, filters=None):

Callers

nothing calls this directly

Calls 2

LZMAFileClass · 0.85
replaceMethod · 0.45

Tested by

no test coverage detected