Open bzip2 compressed tar archive name for reading or writing. Appending is not allowed.
(cls, name, mode="r", fileobj=None, compresslevel=9, **kwargs)
| 1889 | |
| 1890 | @classmethod |
| 1891 | def bz2open(cls, name, mode="r", fileobj=None, compresslevel=9, **kwargs): |
| 1892 | """Open bzip2 compressed tar archive name for reading or writing. |
| 1893 | Appending is not allowed. |
| 1894 | """ |
| 1895 | if mode not in ("r", "w", "x"): |
| 1896 | raise ValueError("mode must be 'r', 'w' or 'x'") |
| 1897 | |
| 1898 | try: |
| 1899 | from bz2 import BZ2File |
| 1900 | except ImportError: |
| 1901 | raise CompressionError("bz2 module is not available") from None |
| 1902 | |
| 1903 | fileobj = BZ2File(fileobj or name, mode, compresslevel=compresslevel) |
| 1904 | |
| 1905 | try: |
| 1906 | t = cls.taropen(name, mode, fileobj, **kwargs) |
| 1907 | except (OSError, EOFError) as e: |
| 1908 | fileobj.close() |
| 1909 | if mode == 'r': |
| 1910 | raise ReadError("not a bzip2 file") from e |
| 1911 | raise |
| 1912 | except: |
| 1913 | fileobj.close() |
| 1914 | raise |
| 1915 | t._extfileobj = False |
| 1916 | return t |
| 1917 | |
| 1918 | @classmethod |
| 1919 | def xzopen(cls, name, mode="r", fileobj=None, preset=None, **kwargs): |
nothing calls this directly
no test coverage detected