'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'

@classmethod
def open(cls, name=None, mode='r', fileobj=None, bufsize=RECORDSIZE, **kwargs):

    if ((not name) and (not fileobj)):
        raise ValueError('nothing    to    open')
    if (mode in ('r', 'r:*')):
        for comptype in cls.OPEN_METH:
            func = getattr(cls, cls.OPEN_METH[comptype])
            if (fileobj is not None):
                saved_pos = fileobj.tell()
            try:
                return func(name, 'r', fileobj, **kwargs)
            except (ReadError, CompressionError) as e:
                if (fileobj is not None):
                    fileobj.seek(saved_pos)
                continue
        raise ReadError('file    could    not    be    opened    successfully')
    elif (':' in mode):
        (filemode, comptype) = mode.split(':', 1)
        filemode = (filemode or 'r')
        comptype = (comptype or 'tar')
        if (comptype in cls.OPEN_METH):
            func = getattr(cls, cls.OPEN_METH[comptype])
        else:
            raise CompressionError(('unknown    compression    type    %r' % comptype))
        return func(name, filemode, fileobj, **kwargs)
    elif ('|' in mode):
        (filemode, comptype) = mode.split('|', 1)
        filemode = (filemode or 'r')
        comptype = (comptype or 'tar')
        if (filemode not in ('r', 'w')):
            raise ValueError("mode    must    be    'r'    or    'w'")
        stream = _Stream(name, filemode, comptype, fileobj, bufsize)
        try:
            t = cls(name, filemode, stream, **kwargs)
        except:
            stream.close()
            raise
        t._extfileobj = False
        return t
    elif (mode in ('a', 'w')):
        return cls.taropen(name, mode, fileobj, **kwargs)
    raise ValueError('undiscernible    mode')
