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

Method open

Lib/tarfile.py:1842–1948  ·  view source on GitHub ↗

Open a tar archive for reading, writing or appending. Return an appropriate TarFile class. mode: 'r' or 'r:*' open for reading with transparent compression 'r:' open for reading exclusively uncompressed 'r:gz' open for reading wit

(cls, name=None, mode="r", fileobj=None, bufsize=RECORDSIZE, **kwargs)

Source from the content-addressed store, hash-verified

1840
1841 @classmethod
1842 def open(cls, name=None, mode="r", fileobj=None, bufsize=RECORDSIZE, **kwargs):
1843 """Open a tar archive for reading, writing or appending. Return
1844 an appropriate TarFile class.
1845
1846 mode:
1847 'r' or 'r:*' open for reading with transparent compression
1848 'r:' open for reading exclusively uncompressed
1849 'r:gz' open for reading with gzip compression
1850 'r:bz2' open for reading with bzip2 compression
1851 'r:xz' open for reading with lzma compression
1852 'r:zst' open for reading with zstd compression
1853 'a' or 'a:' open for appending, creating the file if necessary
1854 'w' or 'w:' open for writing without compression
1855 'w:gz' open for writing with gzip compression
1856 'w:bz2' open for writing with bzip2 compression
1857 'w:xz' open for writing with lzma compression
1858 'w:zst' open for writing with zstd compression
1859
1860 'x' or 'x:' create a tarfile exclusively without compression, raise
1861 an exception if the file is already created
1862 'x:gz' create a gzip compressed tarfile, raise an exception
1863 if the file is already created
1864 'x:bz2' create a bzip2 compressed tarfile, raise an exception
1865 if the file is already created
1866 'x:xz' create an lzma compressed tarfile, raise an exception
1867 if the file is already created
1868 'x:zst' create a zstd compressed tarfile, raise an exception
1869 if the file is already created
1870
1871 'r|*' open a stream of tar blocks with transparent compression
1872 'r|' open an uncompressed stream of tar blocks for reading
1873 'r|gz' open a gzip compressed stream of tar blocks
1874 'r|bz2' open a bzip2 compressed stream of tar blocks
1875 'r|xz' open an lzma compressed stream of tar blocks
1876 'r|zst' open a zstd compressed stream of tar blocks
1877 'w|' open an uncompressed stream for writing
1878 'w|gz' open a gzip compressed stream for writing
1879 'w|bz2' open a bzip2 compressed stream for writing
1880 'w|xz' open an lzma compressed stream for writing
1881 'w|zst' open a zstd compressed stream for writing
1882 """
1883
1884 if not name and not fileobj:
1885 raise ValueError("nothing to open")
1886
1887 if mode in ("r", "r:*"):
1888 # Find out which *open() is appropriate for opening the file.
1889 def not_compressed(comptype):
1890 return cls.OPEN_METH[comptype] == 'taropen'
1891 error_msgs = []
1892 for comptype in sorted(cls.OPEN_METH, key=not_compressed):
1893 func = getattr(cls, cls.OPEN_METH[comptype])
1894 if fileobj is not None:
1895 saved_pos = fileobj.tell()
1896 try:
1897 return func(name, "r", fileobj, **kwargs)
1898 except (ReadError, CompressionError) as e:
1899 error_msgs.append(f'- method {comptype}: {e!r}')

Callers 2

__init__Method · 0.45
mainFunction · 0.45

Calls 15

sortedFunction · 0.85
getattrFunction · 0.85
CompressionErrorClass · 0.85
_StreamClass · 0.85
taropenMethod · 0.80
ReadErrorClass · 0.70
funcFunction · 0.50
clsClass · 0.50
tellMethod · 0.45
appendMethod · 0.45
seekMethod · 0.45
joinMethod · 0.45

Tested by

no test coverage detected