def open_archive(fs_url, archive):
it = pkg_resources.iter_entry_points('<STR_LIT>')<EOL>entry_point = next((ep for ep in it if archive.endswith(ep.name)), None)<EOL>if entry_point is None:<EOL><INDENT>raise UnsupportedProtocol(<EOL>'<STR_LIT>'.format(archive))<EOL><DEDENT>try:<EOL><INDENT>archive_opener = entry_point.load()<EOL><DEDENT>except pkg_resources.DistributionNotFound as df: <EOL><INDENT>six.raise_from(UnsupportedProtocol(<EOL>'<STR_LIT>'.format(entry_point.name, df.req)), None)<EOL><DEDENT>try:<EOL><INDENT>binfile = None<EOL>archive_fs = None<EOL>fs = open_fs(fs_url)<EOL>if issubclass(archive_opener, base.ArchiveFS):<EOL><INDENT>try:<EOL><INDENT>binfile = fs.openbin(archive, '<STR_LIT>')<EOL><DEDENT>except errors.ResourceNotFound:<EOL><INDENT>binfile = fs.openbin(archive, '<STR_LIT:w>')<EOL><DEDENT>except errors.ResourceReadOnly:<EOL><INDENT>binfile = fs.openbin(archive, '<STR_LIT:r>')<EOL>archive_opener = archive_opener._read_fs_cls<EOL><DEDENT><DEDENT>elif issubclass(archive_opener, base.ArchiveReadFS):<EOL><INDENT>binfile = fs.openbin(archive, '<STR_LIT:r>')<EOL><DEDENT>if not hasattr(binfile, '<STR_LIT:name>'):<EOL><INDENT>binfile.name = basename(archive)<EOL><DEDENT>archive_fs = archive_opener(binfile)<EOL><DEDENT>except Exception:<EOL><INDENT>getattr(archive_fs, '<STR_LIT>', lambda: None)()<EOL>getattr(binfile, '<STR_LIT>', lambda: None)()<EOL>raise<EOL><DEDENT>else:<EOL><INDENT>return archive_fs<EOL><DEDENT>
Open an archive on a filesystem.

    This function tries to mimick the behaviour of `fs.open_fs` as closely
    as possible: it accepts either a FS URL or a filesystem instance, and
    will close all resources it had to open.

    Arguments:
        fs_url (FS or text_type): a FS URL, or a filesystem
            instance, where the archive file is located.
        archive (text_type): the path to the archive file on the
            given filesystem.

    Raises:
        `fs.opener._errors.Unsupported`: when the archive type is not supported
            (either the file extension is unknown or the opener requires unmet
            dependencies).

    Example:
        >>> from fs.archive import open_archive
        >>> with open_archive('mem://', 'test.tar.gz') as archive_fs:
        ...     type(archive_fs)
        <class 'fs.archive.tarfs.TarFS'>

    Hint:
        This function finds the entry points defined in group
        ``fs.archive.open_archive``, using the names of the entry point
        as the registered extension.