3 (\@s6dZddlmZddlZddlZddlZddlZddlZddlZddl Z ddl Z ddl m Z ddl mZmZmZddlmZddlmZddlmZdd lmZdd lmZmZmZdd lmZdd lm Z!dd l"m#Z#m$Z$m%Z%m&Z&dd l'm(Z(m)Z)m*Z*m+Z+ddl,m-Z-ddl.m/Z/ddl0m1Z1ddl2m3Z3ddl4m5Z5ddl6m7Z7ddl8m9Z9ddl:m;Z;mZ>m?Z?ddl@mAZAddlBmCZCddlDmEZEeCr@ddlmFZFddlGmHZHmIZImJZJmKZKmLZLmMZMmNZNmOZOmPZPmQZQddlmRZRddlSmTZTddl4mUZUddlVmWZWddl"mXZXeHeYeYeIeYfZZeHeJd fZ[eHe\eRe[eIe\fZ]d!d"d#gZ^dOdPdQdRdSdTgZ_ej`eaZbd+d,Zcd-d.ZdGd/d0d0eeZfd1d2ZgGd3d4d4eeZhd5d6Zid7d8ZjdUd9d:ZkdVd;d<ZlGd=d>d>emZnGd?d"d"emZoGd@d#d#emZpdAdBZqdCdDZrdEdFZsdGdHZtdIdJZuGdKdLdLemZve dMdNZwdS)Wz!Routines related to PyPI, indexes)absolute_importN) namedtuple)html5librequestssix)unescape) specifiers)canonicalize_name)parse) HTTPError RetryErrorSSLError)request)HAS_TLSis_url path_to_url url_to_path)BestVersionAlreadyInstalledDistributionNotFoundInvalidWheelFilenameUnsupportedWheel)InstallationCandidate) FormatControl)PyPI)Link) get_supported) ipaddress) indent_log)ARCHIVE_EXTENSIONSSUPPORTED_EXTENSIONSWHEEL_EXTENSIONnormalize_pathredact_password_from_url)check_requires_python)MYPY_CHECK_RUNNING)Wheel)Logger) TupleOptionalAnyListUnionCallableSetSequenceIterableMutableMapping) _BaseVersion)Response) Pep425Tag)InstallRequirement) PipSession.rFoundCandidates PackageFinderhttps* localhost 127.0.0.0/8::1/128filesshcCsBddlm}x0|jD]&}|jj|r|t|dkr|SqWdS)zgLook for VCS schemes in the URL. Returns the matched VCS scheme, or None if there's no match. r) VcsSupportz+:N)Zpip._internal.vcsr?schemeslower startswithlen)urlr?schemerFf/private/var/folders/pf/wv4htv3x0qs2c2mp0dnn0kchsvlck3/T/pip-build-k1a8l1r5/pip/pip/_internal/index.py_match_vcs_schemeOs   rHcCs*t|j}xtD]}|j|rdSqWdS)z2Return whether the URL looks like an archive. TF)rfilenamerendswith)rDrIbad_extrFrFrG_is_url_like_archive\s    rLcseZdZfddZZS)_NotHTMLcs"tt|j||||_||_dS)N)superrM__init__ content_type request_desc)selfrPrQ) __class__rFrGrOhsz_NotHTML.__init__)__name__ __module__ __qualname__rO __classcell__rFrF)rSrGrMgsrMcCs.|jjdd}|jjds*t||jjdS)zCheck the Content-Type header to ensure the response contains HTML. Raises `_NotHTML` if the content type is not text/html. z Content-Typez text/htmlN)headersgetrArBrMrmethod)responserPrFrFrG_ensure_html_headerosr]c@s eZdZdS)_NotHTTPN)rTrUrVrFrFrFrGr^zsr^cCsDtj|\}}}}}|dkr"t|j|dd}|jt|dS)zSend a HEAD request to the URL, and ensure the response contains HTML. Raises `_NotHTTP` if the URL is not available for a HEAD request, or `_NotHTML` if the content type is not text/html. httpr8T)allow_redirectsN>r8r_) urllib_parseurlsplitr^headraise_for_statusr])rDsessionrEnetlocpathqueryfragmentresprFrFrG_ensure_html_response~s rkcCsLt|rt||dtjdt||j|dddd}|jt||S)aAccess an HTML page with GET, and return the response. This consists of three parts: 1. If the URL looks suspiciously like an archive, send a HEAD first to check the Content-Type is HTML, to avoid downloading a large file. Raise `_NotHTTP` if the content type cannot be determined, or `_NotHTML` if it is not HTML. 2. Actually perform the request. Raise HTTP exceptions on network failures. 3. Check the Content-Type header to make sure we got HTML, and raise `_NotHTML` otherwise. )rezGetting page %sz text/htmlz max-age=0)Acceptz Cache-Control)rY)rLrkloggerdebugr"rZrdr])rDrerjrFrFrG_get_html_responses  rocCs|dkrtj}|d||dS)Nz%Could not fetch URL %s: %s - skipping)rmrn)linkreasonmethrFrFrG_handle_get_page_failsrsc Cs |dkrtd|jjddd}t|}|r@tjd||dStj|\}}}}}}|dkrtj j t j |r|j ds|d7}tj|d}tjd |yt||d }WnFtk rtjd |Yn8tk r}ztjd ||j|jWYdd}~Xntk r2}zt||WYdd}~Xntk r^}zt||WYdd}~Xntk r}z&d } | t|7} t|| tjdWYdd}~Xnftjk r}zt|d|WYdd}~Xn4tjk rt|dYnXt|j|j|jSdS)Nz?_get_html_page() missing 1 required keyword argument: 'session'#rzCannot look at %s URL %sr=/z index.htmlz# file: URL is directory, getting %s)rezQSkipping page %s because it looks like an archive, and cannot be checked by HEAD.zhsz1FoundCandidates.from_specifier..css|]}t|jVqdS)N)rr)rcrFrFrG qsz1FoundCandidates.from_specifier..) prereleases)filter)clsr specifierrrrrFrFrGfrom_specifier_s   zFoundCandidates.from_specifiercCs t|jS)z(Iterate through all candidates. )iterr)rRrFrFrGiter_allwszFoundCandidates.iter_allcsfddjDS)z`Iterate through candidates matching the versions associated with this instance. c3s"|]}t|jjkr|VqdS)N)rrr)rr)rRrFrGrsz2FoundCandidates.iter_applicable..)r)rRrF)rRrGiter_applicable}szFoundCandidates.iter_applicablecCst|j}|jj|S)zdReturn the best candidate available, or None if no applicable candidates are found. )listrrr)rRrrFrFrGget_bests zFoundCandidates.get_bestN) rTrUrV__doc__rO classmethodrrrrrFrFrFrGr6Ds  c @seZdZdZdddZddZed dd Zd d Zd d Z ddZ d!ddZ ddZ ddZ ejdZddZddZddZddZdS)"r7zThis finds packages. This is meant to match easy_install's technique for looking for packages, by reading pages and looking for appropriate links. FNc Cs|dkrtdg|_x:|D]2} | jdrBt| } tjj| rB| } |jj| qW||_t |_ |ppt t t |_ dd|r|ngD|_ ||_||_t||| | d}t|| d|_tsx8tj|j|jD]$} tj| }|jdkrtjd PqWdS) a"Create a PackageFinder. :param format_control: A FormatControl object or None. Used to control the selection of source packages / binary packages when consulting the index and links. :param platform: A string or None. If None, searches for packages that are supported by the current system. Otherwise, will find packages that can be built on the platform passed in. These packages will only be downloaded for distribution: they will not be built locally. :param versions: A list of strings or None. This is passed directly to pep425tags.py in the get_supported() method. :param abi: A string or None. This is passed directly to pep425tags.py in the get_supported() method. :param implementation: A string or None. This is passed directly to pep425tags.py in the get_supported() method. :param prefer_binary: Whether to prefer an old, but valid, binary dist over a new source dist. Nz>PackageFinder() missing 1 required keyword argument: 'session'~cSsg|]}d|dfqS)r9rF)rhostrFrFrG sz*PackageFinder.__init__..)rplatformabiimpl)rrr8zipip is configured with locations that require TLS/SSL, however the ssl module in Python is not available.)rw find_linksrBr!rzrgexistsappend index_urlsset logged_linksrformat_controlsecure_originsallow_all_prereleasesrerrcandidate_evaluatorr itertoolschainraryrErmwarning)rRrrr trusted_hostsrerrrrimplementationrrpnew_linkrparsedrFrFrGrOs>"       zPackageFinder.__init__cCsbg}|jr:|jtjgkr:|jdjdjdd|jD|jrX|jdjdj|jdj|S)NzLooking in indexes: {}z, css|]}t|VqdS)N)r")rrDrFrFrGrsz8PackageFinder.get_formatted_locations..zLooking in links: {} )rr simple_urlrformatjoinr)rRlinesrFrFrGget_formatted_locationssz%PackageFinder.get_formatted_locationscsggfdd}x|D]}tjj|}|jd}|s>|r|rH|}nt|}tjj|r|rtjj|}xFtj|D]}|tjj||qxWq|rj |qt j dj |qtjj |r||qt j d|qt|rj |qt j d|qWfS)zt Sort locations into "files" (archives) and "urls", and return a pair of lists (files,urls) cs8t|}tj|ddddkr*j|n j|dS)NF)strictrz text/html)r mimetypes guess_typer)rgrD)filesurlsrFrG sort_paths z0PackageFinder._sort_locations..sort_pathzfile:z)Path '{0}' is ignored: it is a directory.z:Url '%s' is ignored: it is neither a file nor a directory.zQUrl '%s' is ignored. It is either a non-existing path or lacks a specific scheme.)rzrgrrBrr{realpathlistdirrrrmrrisfiler) locations expand_dirrrD is_local_path is_file_urlrgitemrF)rrrG_sort_locationss>           zPackageFinder._sort_locationsc Csltjt|}|j|j|jf}|djddd }x t|jD]}||dkr`|ddkr`q@yht j t |dt j s|ddkr|dn |djd}t jt |dt j r|dn |djd}WnJtk r|dr|dj|djkr|ddkrw@YnX||kr q@|d|dkrP|ddkrP|ddk rPq@dSW|jd|j|jd S) Nr+rur9utf8TzThe repository located at %s is not a trusted or secure host and is being ignored. If this repository is available via HTTPS we recommend you use HTTPS instead, otherwise you may silence this warning and allow it anyway with '--trusted-host %s'.F)raryrrEhostnameportrsplitSECURE_ORIGINSrr ip_address isinstancer text_typedecode ip_network ValueErrorrAr) rRrmrroriginprotocol secure_originaddrnetworkrFrFrG_validate_secure_origin=s>  z%PackageFinder._validate_secure_origincs fddfdd|jDS)zReturns the locations found via self.index_urls Checks the url_name on the main (first in the list) index and use this url_name to produce all locations cs,tj|tjt}|jds(|d}|S)Nrv) posixpathrraquoter rJ)rDloc) project_namerFrGmkurl_pypi_urls  z?PackageFinder._get_index_urls_locations..mkurl_pypi_urlcsg|] }|qSrFrF)rrD)rrFrGrsz;PackageFinder._get_index_urls_locations..)r)rRrrF)rrrG_get_index_urls_locationss z'PackageFinder._get_index_urls_locationsc sjj|}j|\}}jjdd\}}ddtj||D}fddtjdd|Ddd|DD}tjd t||x|D]} tjd | qWt|} j j | } t || | } j d djD| } g}xJj ||D]:}tjd |jt|jj |j| Wd QRXqWj || }|r^|jddtjddjdd|D|| |S)aFind all available InstallationCandidate for project_name This checks index_urls and find_links. All versions found are returned as an InstallationCandidate list. See _link_package_versions for details on which files are accepted T)rcss|]}t|VqdS)N)r)rrDrFrFrGrsz4PackageFinder.find_all_candidates..csg|]}jt|r|qSrF)rrm)rrp)rRrFrGrsz5PackageFinder.find_all_candidates..css|]}t|VqdS)N)r)rrDrFrFrGrscss|]}t|VqdS)N)r)rrDrFrFrGrsz,%d location(s) to search for versions of %s:z* %scss|]}t|dVqdS)z-fN)r)rrDrFrFrGrszAnalyzing links from page %sN)reversezLocal files found: %sz, cSsg|]}t|jjqSrF)rrrD)rrrFrFrGrs)rrrrrrmrnrCr rZget_allowed_formatsSearch_package_versions _get_pagesrDrextend iter_linkssortr)rRrindex_locationsindex_file_loc index_url_loc fl_file_loc fl_url_locfile_locations url_locationsrcanonical_nameformatssearchfind_links_versions page_versionspage file_versionsrF)rRrGfind_all_candidatessD            z!PackageFinder.find_all_candidatescCs0|dkrtj}tj|j|||jp&d|jdS)zFind matches for the given project and specifier. If given, `specifier` should implement `filter` to allow version filtering (e.g. ``packaging.specifiers.SpecifierSet``). Returns a `FoundCandidates` instance. N)rrr)r SpecifierSetr6rrrr)rRrrrFrFrGfind_candidatess zPackageFinder.find_candidatescCs|j|j|j}|j}d}|jdk r2t|jj}dd}|dkrl|dkrltjd|||j t d|d}|r|dks|j|krd}| r|dk r|rtj d|ntj d ||jdS|rtj d |||j t tj d |j||j |jS) zTry to find a Link matching req Expects req, an InstallRequirement and upgrade, a boolean Returns a Link if found, Raises DistributionNotFound or BestVersionAlreadyInstalled otherwise NcSs djtdd|DtdpdS)Nz, cSsh|]}t|jqSrF)rr)rrrFrFrGr szKPackageFinder.find_requirement.._format_versions..)rnone)rsorted parse_version)Z cand_iterrFrFrG_format_versionss  z8PackageFinder.find_requirement.._format_versionszNCould not find a version that satisfies the requirement %s (from versions: %s)z%No matching distribution found for %sFTzLExisting installed version (%s) is most up-to-date and satisfies requirementzUExisting installed version (%s) satisfies requirement (most up-to-date version is %s)z=Installed version (%s) is most up-to-date (past versions: %s)z)Using version %s (newest of versions: %s))rnamerr satisfied_byrrrmcriticalrrrnrrr)rRrequpgraderbest_candidateinstalled_versionrbest_installedrFrFrGfind_requirementsN     zPackageFinder.find_requirementccsJt}x>|D]6}||krq |j|t||jd}|dkr|j|q|j|qW||S)z Returns elements of links in order, non-egg links first, egg links second, while eliminating duplicates )rr# egg_fragmentr)rRlinkseggsno_eggsr$rprFrFrG _sort_linksVs    zPackageFinder._sort_linkscCs:g}x0|j|D]"}|j||}|dk r|j|qW|S)N)r)_link_package_versionsr)rRr&rresultrprrFrFrGrgs  zPackageFinder._package_versionscCs(||jkr$tjd|||jj|dS)NzSkipping link %s; %s)rrmrnr#)rRrprqrFrFrG_log_skipped_linkts zPackageFinder._log_skipped_linkc CsDd}|jr|j}|j}n |j\}}|s:|j|ddS|tkrV|j|d|dSd|jkr~|tkr~|j|d|jdSd|jkr|dkr|j|ddS|tkr&yt |j }Wn t k r|j|d dSXt |j |jkr|j|d |jdS|jj|s |j|d dS|j}d |jkrR|tkrR|j|d |jdS|sdt||j}|s|j|d|jdS|jj|}|r|d|j}|jd}|tjddkr|j|ddSyt|j} Wn.tjk r tjd|j |jd} YnX| s(tjd||jdStjd||t|j||S)z'Return an InstallationCandidate or NoneNz not a filezunsupported archive format: %sbinaryzNo binaries permitted for %smacosx10z.zipz macosx10 onezinvalid wheel filenamezwrong project name (not %s)z%it is not compatible with this PythonsourcezNo sources permitted for %szMissing project version for %sruzPython version is incorrectz3Package %s has an invalid Requires-Python entry: %sTzaThe package %s is incompatible with the python version in use. Acceptable python versions are: %szFound link %s, version: %s)r%extsplitextr,rr r suppliedrgr%rIrr r canonicalrrr_egg_info_matches_py_version_rerstartgroupsysr#requires_pythonrInvalidSpecifierrmrnr) rRrprregg_infor1rr py_versionsupport_this_pythonrFrFrGr*zs             z$PackageFinder._link_package_versions) FNNNNNNNF)F)N)rTrUrVrrOr staticmethodrrrrrr"rrcompiler6r)rr,r*rFrFrFrGr7s0 T 9JF L  cCsLx6t|D]*\}}|dkrq t|d||kr |Sq Wtdj||dS)aFind the separator's index based on the package's canonical name. `egg_info` must be an egg info string for the given package, and `canonical_name` must be the package's canonical name. This function is needed since the canonicalized name does not necessarily have the same length as the egg info's name part. An example:: >>> egg_info = 'foo__bar-1.0' >>> canonical_name = 'foo-bar' >>> _find_name_version_sep(egg_info, canonical_name) 8 -Nz{} does not match {}) enumerater rr)r<r irrFrFrG_find_name_version_seps rDc Cs@yt||d}Wntk r&dSX||d}|s`` tag in the HTML document. If present, its href attribute denotes the base URL of anchor tags in the document. If there is no such tag (or if it does not have a valid href attribute), the HTML file's URL is used as the base URL. :param document: An HTML document representation. The current implementation expects the result of ``html5lib.parse()``. :param page_url: The URL of the HTML document. z.//basehrefN)findallrZ)documentZpage_urlbaserErFrFrG_determine_base_urls  rIcCs2|r.d|kr.tj|d\}}d|kr.|dSdS)zBDetermine if we have any encoding information in our headers. z Content-TypecharsetN)cgi parse_header)rYrPparamsrFrFrG_get_encoding_from_headers s  rNcCsPtj|}|jdkr(tjtj|j}ntjtj|jdd}tj |j |dS)zMakes sure a link is fully encoded. That is, if a ' ' shows up in the link, it will be rewritten to %20 (while not over-quoting % or other characters).rXz/@)safe)rg) raryrfr| pathname2urlr}rgrunquote urlunparse_replace)rDr+rgrFrFrG _clean_links  rTc@s*eZdZdZd ddZddZddZdS) rz'Represents one page, along with its URLNcCs||_||_||_dS)N)rrDrY)rRrrDrYrFrFrGrO2szHTMLPage.__init__cCs t|jS)N)r"rD)rRrFrFrG__str__8szHTMLPage.__str__ccstj|jt|jdd}t||j}xb|jdD]T}|jdr0|jd}t t j ||}|jd}|rnt |nd}t ||j|dVq0WdS)zYields all links in the pageF)transport_encodingnamespaceHTMLElementsz.//arEzdata-requires-pythonN)r:)rr rrNrYrIrDrFrZrTrar~rr)rRrGbase_urlanchorrErD pyrequirerFrFrGr;s    zHTMLPage.iter_links)N)rTrUrVrrOrUrrFrFrFrGr/s rrzsupplied canonical formats)r8r9r9)r9r:r9)r9r;r9)r9r<r9)r=r9N)r>r9r9)N)N)xr __future__rrKrloggingrrzrrr9 collectionsr pip._vendorrrrZpip._vendor.distlib.compatrZpip._vendor.packagingrpip._vendor.packaging.utilsr Zpip._vendor.packaging.versionr rZpip._vendor.requests.exceptionsr r r Zpip._vendor.six.moves.urllibrarr|Zpip._internal.downloadrrrrZpip._internal.exceptionsrrrrZpip._internal.models.candidaterZ#pip._internal.models.format_controlrZpip._internal.models.indexrZpip._internal.models.linkrZpip._internal.pep425tagsrZpip._internal.utils.compatrZpip._internal.utils.loggingrZpip._internal.utils.miscrrr r!r"Zpip._internal.utils.packagingr#Zpip._internal.utils.typingr$Zpip._internal.wheelr%r&Ztypingr'r(r)r*r+r,r-r.r/r0r1Zpip._vendor.requestsr2r3Zpip._internal.reqr4r5rZ SecureOriginZBuildTagrZCandidateSortingKey__all__r getLoggerrTrmrHrL ExceptionrMr]r^rkrorsrobjectrr6r7rDr5rIrNrTrrrFrFrFrGs                   0           6  6AJB