def unpack_archive(filename, extract_dir=None, format=None):
if extract_dir is None:<EOL><INDENT>extract_dir = os.getcwd()<EOL><DEDENT>if format is not None:<EOL><INDENT>try:<EOL><INDENT>format_info = _UNPACK_FORMATS[format]<EOL><DEDENT>except KeyError:<EOL><INDENT>raise ValueError("<STR_LIT>".format(format))<EOL><DEDENT>func = format_info[<NUM_LIT:1>]<EOL>func(filename, extract_dir, **dict(format_info[<NUM_LIT:2>]))<EOL><DEDENT>else:<EOL><INDENT>format = _find_unpack_format(filename)<EOL>if format is None:<EOL><INDENT>raise ReadError("<STR_LIT>".format(filename))<EOL><DEDENT>func = _UNPACK_FORMATS[format][<NUM_LIT:1>]<EOL>kwargs = dict(_UNPACK_FORMATS[format][<NUM_LIT:2>])<EOL>func(filename, extract_dir, **kwargs)<EOL><DEDENT>
Unpack an archive.

    `filename` is the name of the archive.

    `extract_dir` is the name of the target directory, where the archive
    is unpacked. If not provided, the current working directory is used.

    `format` is the archive format: one of "zip", "tar", or "gztar". Or any
    other registered format. If not provided, unpack_archive will use the
    filename extension and see if an unpacker was registered for that
    extension.

    In case none is found, a ValueError is raised.