MCPcopy Index your code
hub / github.com/RustPython/RustPython / xzopen

Method xzopen

Lib/tarfile.py:2020–2045  ·  view source on GitHub ↗

Open lzma compressed tar archive name for reading or writing. Appending is not allowed.

(cls, name, mode="r", fileobj=None, preset=None, **kwargs)

Source from the content-addressed store, hash-verified

2018
2019 @classmethod
2020 def xzopen(cls, name, mode="r", fileobj=None, preset=None, **kwargs):
2021 """Open lzma compressed tar archive name for reading or writing.
2022 Appending is not allowed.
2023 """
2024 if mode not in ("r", "w", "x"):
2025 raise ValueError("mode must be 'r', 'w' or 'x'")
2026
2027 try:
2028 from lzma import LZMAFile, LZMAError
2029 except ImportError:
2030 raise CompressionError("lzma module is not available") from None
2031
2032 fileobj = LZMAFile(fileobj or name, mode, preset=preset)
2033
2034 try:
2035 t = cls.taropen(name, mode, fileobj, **kwargs)
2036 except (LZMAError, EOFError) as e:
2037 fileobj.close()
2038 if mode == 'r':
2039 raise ReadError("not an lzma file") from e
2040 raise
2041 except:
2042 fileobj.close()
2043 raise
2044 t._extfileobj = False
2045 return t
2046
2047 @classmethod
2048 def zstopen(cls, name, mode="r", fileobj=None, level=None, options=None,

Callers

nothing calls this directly

Calls 5

closeMethod · 0.95
LZMAFileClass · 0.90
CompressionErrorClass · 0.85
taropenMethod · 0.80
ReadErrorClass · 0.70

Tested by

no test coverage detected