<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def _extract_package(deps_dir, pkg_path):
 """ Extract a .whl, .zip, .tar.gz or .tar.bz2 into a package path to use when running CI tasks :param deps_dir: A unicode string of the directory the package should be extracted to :param pkg_path: A unicode string of the path to the archive """


    if pkg_path.endswith('.exe'):
        try:
            zf = None
            zf = zipfile.ZipFile(pkg_path, 'r')
            # Exes have a PLATLIB folder containing everything we want
            for zi in zf.infolist():
                if not zi.filename.startswith('PLATLIB'):
                    continue
                data = _extract_info(zf, zi)
                if data is not None:
                    dst_path = os.path.join(deps_dir, zi.filename[8:])
                    dst_dir = os.path.dirname(dst_path)
                    if not os.path.exists(dst_dir):
                        os.makedirs(dst_dir)
                    with open(dst_path, 'wb') as f:
                        f.write(data)
        finally:
            if zf:
                zf.close()
        return

    if pkg_path.endswith('.whl'):
        try:
            zf = None
            zf = zipfile.ZipFile(pkg_path, 'r')
            # Wheels contain exactly what we need and nothing else
            zf.extractall(deps_dir)
        finally:
            if zf:
                zf.close()
        return

    # Source archives may contain a bunch of other things.
    # The following code works for the packages coverage and
    # configparser, which are the two we currently require that
    # do not provide wheels

    try:
        ar = None
        ar = _open_archive(pkg_path)

        pkg_name = None
        base_path = _archive_single_dir(ar) or ''
        if len(base_path):
            if '-' in base_path:
                pkg_name, _ = base_path.split('-', 1)
            base_path += '/'

        base_pkg_path = None
        if pkg_name is not None:
            base_pkg_path = base_path + pkg_name + '/'
        src_path = base_path + 'src/'

        members = []
        for info in _list_archive_members(ar):
            fn = _info_name(info)
            if base_pkg_path is not None and fn.startswith(base_pkg_path):
                dst_path = fn[len(base_pkg_path) - len(pkg_name) - 1:]
                members.append((info, dst_path))
                continue
            if fn.startswith(src_path):
                members.append((info, fn[len(src_path):]))
                continue

        for info, path in members:
            info_data = _extract_info(ar, info)
            # Dirs won't return a file
            if info_data is not None:
                dst_path = os.path.join(deps_dir, path)
                dst_dir = os.path.dirname(dst_path)
                if not os.path.exists(dst_dir):
                    os.makedirs(dst_dir)
                with open(dst_path, 'wb') as f:
                    f.write(info_data)
    finally:
        if ar:
            ar.close()