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

Method bz2open

Lib/tarfile.py:2011–2036  ·  view source on GitHub ↗

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

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

Source from the content-addressed store, hash-verified

2009
2010 @classmethod
2011 def bz2open(cls, name, mode="r", fileobj=None, compresslevel=9, **kwargs):
2012 """Open bzip2 compressed tar archive name for reading or writing.
2013 Appending is not allowed.
2014 """
2015 if mode not in ("r", "w", "x"):
2016 raise ValueError("mode must be 'r', 'w' or 'x'")
2017
2018 try:
2019 from bz2 import BZ2File
2020 except ImportError:
2021 raise CompressionError("bz2 module is not available") from None
2022
2023 fileobj = BZ2File(fileobj or name, mode, compresslevel=compresslevel)
2024
2025 try:
2026 t = cls.taropen(name, mode, fileobj, **kwargs)
2027 except (OSError, EOFError) as e:
2028 fileobj.close()
2029 if mode == 'r':
2030 raise ReadError("not a bzip2 file") from e
2031 raise
2032 except:
2033 fileobj.close()
2034 raise
2035 t._extfileobj = False
2036 return t
2037
2038 @classmethod
2039 def xzopen(cls, name, mode="r", fileobj=None, preset=None, **kwargs):

Callers

nothing calls this directly

Calls 5

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

Tested by

no test coverage detected