package_index.py - "PyPI and direct package downloading...

This preview shows page 1 - 3 out of 18 pages.

"""PyPI and direct package downloading"""import sysimport osimport reimport ioimport shutilimport socketimport base64import hashlibimport itertoolsimport warningsimport configparserimport htmlimport http.clientimport urllib.parseimport urllib.requestimport urllib.errorfrom functools import wrapsimport setuptoolsfrom pkg_resources import (CHECKOUT_DIST, Distribution, BINARY_DIST, normalize_path, SOURCE_DIST,Environment, find_distributions, safe_name, safe_version,to_filename, Requirement, DEVELOP_DIST, EGG_DIST,)from setuptools import ssl_supportfrom distutils import logfrom distutils.errors import DistutilsErrorfrom fnmatch import translatefrom setuptools.wheel import WheelEGG_FRAGMENT = re.compile(r'^egg=([-A-Za-z0-9_.+!]+)$')HREF = re.compile(r"""href\s*=\s*['"]?([^'"> ]+)""", re.I)PYPI_MD5 = re.compile(r'<a href="([^"#]+)">([^<]+)</a>\n\s+\(<a (?:title="MD5 hash"\n\s+)'r'href="[^?]+\?:action=show_md5&amp;digest=([0-9a-f]{32})">md5</a>\)')URL_SCHEME = re.compile('([-+.a-z0-9]{2,}):', re.I).matchEXTENSIONS = ".tar.gz .tar.bz2 .tar .zip .tgz".split()__all__ = ['PackageIndex', 'distros_for_url', 'parse_bdist_wininst','interpret_distro_name',]_SOCKET_TIMEOUT = 15_tmpl = "setuptools/{setuptools.__version__} Python-urllib/{py_major}"user_agent = _tmpl.format(py_major='{}.{}'.format(*sys.version_info), setuptools=setuptools)def parse_requirement_arg(spec):try:return Requirement.parse(spec)except ValueError as e:raise DistutilsError("Not a URL, existing file, or requirement spec: %r" % (spec,)) from edef parse_bdist_wininst(name):"""Return (base,pyversion) or (None,None) for possible .exe name"""
lower = name.lower()base, py_ver, plat = None, None, Noneif lower.endswith('.exe'):if lower.endswith('.win32.exe'):base = name[:-10]plat = 'win32'elif lower.startswith('.win32-py', -16):py_ver = name[-7:-4]base = name[:-16]plat = 'win32'elif lower.endswith('.win-amd64.exe'):base = name[:-14]plat = 'win-amd64'elif lower.startswith('.win-amd64-py', -20):py_ver = name[-7:-4]base = name[:-20]plat = 'win-amd64'return base, py_ver, platdef egg_info_for_url(url):parts = urllib.parse.urlparse(url)scheme, server, path, parameters, query, fragment = partsbase = urllib.parse.unquote(path.split('/')[-1])if server == 'sourceforge.net' and base == 'download': # XXX Yuckbase = urllib.parse.unquote(path.split('/')[-2])if '#' in base:base, fragment = base.split('#', 1)return base, fragmentdef distros_for_url(url, metadata=None):"""Yield egg or source distribution objects that might be found at a URL"""base, fragment = egg_info_for_url(url)for dist in distros_for_location(url, base, metadata):yield distif fragment:match = EGG_FRAGMENT.match(fragment)if match:for dist in interpret_distro_name(url, match.group(1), metadata, precedence=CHECKOUT_DIST):yield distdef distros_for_location(location, basename, metadata=None):"""Yield egg or source distribution objects based on basename"""if basename.endswith('.egg.zip'):basename = basename[:-4] # strip the .zipif basename.endswith('.egg') and '-' in basename:# only one, unambiguous interpretationreturn [Distribution.from_location(location, basename, metadata)]if basename.endswith('.whl') and '-' in basename:wheel = Wheel(basename)if not wheel.is_compatible():return []return [Distribution(location=location,project_name=wheel.project_name,version=wheel.version,# Increase priority over eggs.

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture