environment/lib/python2.7/site-packages/distribute-0.6.31-py2.7.egg/setuptools/archive_util.py
def unpack_tarfile(filename, extract_dir, progress_filter=default_filter):
    """Unpack tar/tar.gz/tar.bz2 `filename` to `extract_dir`

    Raises ``UnrecognizedFormat`` if `filename` is not a tarfile (as determined
    by ``tarfile.open()``).  See ``unpack_archive()`` for an explanation
    of the `progress_filter` argument.
    """

    try:
        tarobj = tarfile.open(filename)
    except tarfile.TarError:
        raise UnrecognizedFormat(
            "%s is not a compressed or uncompressed tar file" % (filename,)
        )

    try:
        tarobj.chown = lambda *args: None   # don't do any chowning!
        for member in tarobj:
            name = member.name
            # don't extract absolute paths or ones with .. in them
            if not name.startswith('/') and '..' not in name:
                prelim_dst = os.path.join(extract_dir, *name.split('/'))
                final_dst = progress_filter(name, prelim_dst)
                # If progress_filter returns None, then we do not extract
                # this file
                # TODO: Do we really need to limit to just these file types?
                # tarobj.extract() will handle all files on all platforms,
                # turning file types that aren't allowed on that platform into
                # regular files.
                if final_dst and (member.isfile() or member.isdir() or
                        member.islnk() or member.issym()):
                    tarobj.extract(member, extract_dir)
                    if final_dst != prelim_dst:
                        shutil.move(prelim_dst, final_dst)
        return True
    finally:
        tarobj.close()
def unpack_tarfile(filename, extract_dir, progress_filter=default_filter):
    """Unpack tar/tar.gz/tar.bz2 `filename` to `extract_dir`

    Raises ``UnrecognizedFormat`` if `filename` is not a tarfile (as determined
    by ``tarfile.open()``).  See ``unpack_archive()`` for an explanation
    of the `progress_filter` argument.
    """

    try:
        tarobj = tarfile.open(filename)
    except tarfile.TarError:
        raise UnrecognizedFormat(
            "%s is not a compressed or uncompressed tar file" % (filename,)
        )

    try:
        tarobj.chown = lambda *args: None   # don't do any chowning!
        for member in tarobj:
            name = member.name
            # don't extract absolute paths or ones with .. in them
            if not name.startswith('/') and '..' not in name:
                prelim_dst = os.path.join(extract_dir, *name.split('/'))
                final_dst = progress_filter(name, prelim_dst)
                # If progress_filter returns None, then we do not extract
                # this file
                # TODO: Do we really need to limit to just these file types?
                # tarobj.extract() will handle all files on all platforms,
                # turning file types that aren't allowed on that platform into
                # regular files.
                if final_dst and (member.isfile() or member.isdir() or
                        member.islnk() or member.issym()):
                    tarobj.extract(member, extract_dir)
                    if final_dst != prelim_dst:
                        shutil.move(prelim_dst, final_dst)
        return True
    finally:
        tarobj.close()
Unpack tar/tar.gz/tar.bz2 `filename` to `extract_dir`

    Raises ``UnrecognizedFormat`` if `filename` is not a tarfile (as determined
    by ``tarfile.open()``).  See ``unpack_archive()`` for an explanation
    of the `progress_filter` argument.