Open lzma compressed tar archive name for reading or writing. Appending is not allowed.
(cls, name, mode="r", fileobj=None, preset=None, **kwargs)
| 1917 | |
| 1918 | @classmethod |
| 1919 | def xzopen(cls, name, mode="r", fileobj=None, preset=None, **kwargs): |
| 1920 | """Open lzma compressed tar archive name for reading or writing. |
| 1921 | Appending is not allowed. |
| 1922 | """ |
| 1923 | if mode not in ("r", "w", "x"): |
| 1924 | raise ValueError("mode must be 'r', 'w' or 'x'") |
| 1925 | |
| 1926 | try: |
| 1927 | from lzma import LZMAFile, LZMAError |
| 1928 | except ImportError: |
| 1929 | raise CompressionError("lzma module is not available") from None |
| 1930 | |
| 1931 | fileobj = LZMAFile(fileobj or name, mode, preset=preset) |
| 1932 | |
| 1933 | try: |
| 1934 | t = cls.taropen(name, mode, fileobj, **kwargs) |
| 1935 | except (LZMAError, EOFError) as e: |
| 1936 | fileobj.close() |
| 1937 | if mode == 'r': |
| 1938 | raise ReadError("not an lzma file") from e |
| 1939 | raise |
| 1940 | except: |
| 1941 | fileobj.close() |
| 1942 | raise |
| 1943 | t._extfileobj = False |
| 1944 | return t |
| 1945 | |
| 1946 | # All *open() methods are registered here. |
| 1947 | OPEN_METH = { |
nothing calls this directly
no test coverage detected