@classmethod<EOL><INDENT>def open(cls, name=None, mode="<STR_LIT:r>", fileobj=None, bufsize=RECORDSIZE, **kwargs):<DEDENT>
if not name and not fileobj:<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>if mode in ("<STR_LIT:r>", "<STR_LIT>"):<EOL><INDENT>for comptype in cls.OPEN_METH:<EOL><INDENT>func = getattr(cls, cls.OPEN_METH[comptype])<EOL>if fileobj is not None:<EOL><INDENT>saved_pos = fileobj.tell()<EOL><DEDENT>try:<EOL><INDENT>return func(name, "<STR_LIT:r>", fileobj, **kwargs)<EOL><DEDENT>except (ReadError, CompressionError) as e:<EOL><INDENT>if fileobj is not None:<EOL><INDENT>fileobj.seek(saved_pos)<EOL><DEDENT>continue<EOL><DEDENT><DEDENT>raise ReadError("<STR_LIT>")<EOL><DEDENT>elif "<STR_LIT::>" in mode:<EOL><INDENT>filemode, comptype = mode.split("<STR_LIT::>", <NUM_LIT:1>)<EOL>filemode = filemode or "<STR_LIT:r>"<EOL>comptype = comptype or "<STR_LIT>"<EOL>if comptype in cls.OPEN_METH:<EOL><INDENT>func = getattr(cls, cls.OPEN_METH[comptype])<EOL><DEDENT>else:<EOL><INDENT>raise CompressionError("<STR_LIT>" % comptype)<EOL><DEDENT>return func(name, filemode, fileobj, **kwargs)<EOL><DEDENT>elif "<STR_LIT:|>" in mode:<EOL><INDENT>filemode, comptype = mode.split("<STR_LIT:|>", <NUM_LIT:1>)<EOL>filemode = filemode or "<STR_LIT:r>"<EOL>comptype = comptype or "<STR_LIT>"<EOL>if filemode not in "<STR_LIT>":<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>stream = _Stream(name, filemode, comptype, fileobj, bufsize)<EOL>try:<EOL><INDENT>t = cls(name, filemode, stream, **kwargs)<EOL><DEDENT>except:<EOL><INDENT>stream.close()<EOL>raise<EOL><DEDENT>t._extfileobj = False<EOL>return t<EOL><DEDENT>elif mode in "<STR_LIT>":<EOL><INDENT>return cls.taropen(name, mode, fileobj, **kwargs)<EOL><DEDENT>raise ValueError("<STR_LIT>")<EOL>
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 with gzip compression
           'r:bz2'      open for reading with bzip2 compression
           'a' or 'a:'  open for appending, creating the file if necessary
           'w' or 'w:'  open for writing without compression
           'w:gz'       open for writing with gzip compression
           'w:bz2'      open for writing with bzip2 compression

           'r|*'        open a stream of tar blocks with transparent compression
           'r|'         open an uncompressed stream of tar blocks for reading
           'r|gz'       open a gzip compressed stream of tar blocks
           'r|bz2'      open a bzip2 compressed stream of tar blocks
           'w|'         open an uncompressed stream for writing
           'w|gz'       open a gzip compressed stream for writing
           'w|bz2'      open a bzip2 compressed stream for writing