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

Method bz2open

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

1990
1991 @classmethod
1992 def bz2open(cls, name, mode="r", fileobj=None, compresslevel=9, **kwargs):
1993 """Open bzip2 compressed tar archive name for reading or writing.
1994 Appending is not allowed.
1995 """
1996 if mode not in ("r", "w", "x"):
1997 raise ValueError("mode must be 'r', 'w' or 'x'")
1998
1999 try:
2000 from bz2 import BZ2File
2001 except ImportError:
2002 raise CompressionError("bz2 module is not available") from None
2003
2004 fileobj = BZ2File(fileobj or name, mode, compresslevel=compresslevel)
2005
2006 try:
2007 t = cls.taropen(name, mode, fileobj, **kwargs)
2008 except (OSError, EOFError) as e:
2009 fileobj.close()
2010 if mode == 'r':
2011 raise ReadError("not a bzip2 file") from e
2012 raise
2013 except:
2014 fileobj.close()
2015 raise
2016 t._extfileobj = False
2017 return t
2018
2019 @classmethod
2020 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