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

Method xzopen

Lib/tarfile.py:2039–2064  ·  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

2037
2038 @classmethod
2039 def xzopen(cls, name, mode="r", fileobj=None, preset=None, **kwargs):
2040 """Open lzma compressed tar archive name for reading or writing.
2041 Appending is not allowed.
2042 """
2043 if mode not in ("r", "w", "x"):
2044 raise ValueError("mode must be 'r', 'w' or 'x'")
2045
2046 try:
2047 from lzma import LZMAFile, LZMAError
2048 except ImportError:
2049 raise CompressionError("lzma module is not available") from None
2050
2051 fileobj = LZMAFile(fileobj or name, mode, preset=preset)
2052
2053 try:
2054 t = cls.taropen(name, mode, fileobj, **kwargs)
2055 except (LZMAError, EOFError) as e:
2056 fileobj.close()
2057 if mode == 'r':
2058 raise ReadError("not an lzma file") from e
2059 raise
2060 except:
2061 fileobj.close()
2062 raise
2063 t._extfileobj = False
2064 return t
2065
2066 @classmethod
2067 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