Y@s$dZddlmZddlZddlZddlmZddlZddlZddl Z ddl Z ddl Z ddl Z ddl Z ddlmZddlmZddlmZddlmZmZmZmZmZdd lmZdd 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,m-Z-ddl.m/Z/ddl0m1Z1m2Z2m3Z3ddl4mZ5ddl6m7Z7ddl8m9Z9ddl:m;Z;ddl<m=Z=dddgZ>dddfdddfdddfdddfdddfdddfgZ?ej@eAZBGdd d eCZDGd!ddeCZEe jFd"e jGd#d$ZHGd%d&d&eCZIGd'd(d(eCZJedd)ZKd*dZLd+d,ZMd-d.ZNd/d0ZOed1d2ZPdS)3z!Routines related to PyPI, indexes)absolute_importN) namedtuple)parse)request) ipaddress)cached_propertysplitextnormalize_pathARCHIVE_EXTENSIONSSUPPORTED_EXTENSIONS)RemovedInPip10Warning) indent_log)check_requires_python)DistributionNotFoundBestVersionAlreadyInstalledInvalidWheelFilenameUnsupportedWheel)HAS_TLSis_url path_to_url url_to_path)Wheel wheel_ext) get_supported)html5librequestssix)canonicalize_name) specifiers)SSLError)unescape FormatControlfmt_ctl_handle_mutual_exclude PackageFinderhttps* localhostz 127.0.0.0/8z::1/128filesshc@seZdZddZddZddZddZd d Zd d Zd dZ ddZ ddZ ddZ dS)InstallationCandidatecCs@||_t||_||_|j|j|jf|_dS)N)project parse_versionversionlocation_key)selfr*r,r-r0(/tmp/pip-build-3puug3g5/pip/pip/index.py__init__>s  zInstallationCandidate.__init__cCsdj|j|j|jS)Nz,)formatr*r,r-)r/r0r0r1__repr__DszInstallationCandidate.__repr__cCs t|jS)N)hashr.)r/r0r0r1__hash__IszInstallationCandidate.__hash__cCs|j|ddS)NcSs ||kS)Nr0)sor0r0r1Msz.InstallationCandidate.__lt__..)_compare)r/otherr0r0r1__lt__LszInstallationCandidate.__lt__cCs|j|ddS)NcSs ||kS)Nr0)r7r8r0r0r1r9Psz.InstallationCandidate.__le__..)r:)r/r;r0r0r1__le__OszInstallationCandidate.__le__cCs|j|ddS)NcSs ||kS)Nr0)r7r8r0r0r1r9Ssz.InstallationCandidate.__eq__..)r:)r/r;r0r0r1__eq__RszInstallationCandidate.__eq__cCs|j|ddS)NcSs ||kS)Nr0)r7r8r0r0r1r9Vsz.InstallationCandidate.__ge__..)r:)r/r;r0r0r1__ge__UszInstallationCandidate.__ge__cCs|j|ddS)NcSs ||kS)Nr0)r7r8r0r0r1r9Ysz.InstallationCandidate.__gt__..)r:)r/r;r0r0r1__gt__XszInstallationCandidate.__gt__cCs|j|ddS)NcSs ||kS)Nr0)r7r8r0r0r1r9\sz.InstallationCandidate.__ne__..)r:)r/r;r0r0r1__ne__[szInstallationCandidate.__ne__cCs&t|tstS||j|jS)N) isinstancer)NotImplementedr.)r/r;methodr0r0r1r:^szInstallationCandidate._compareN) __name__ __module__ __qualname__r2r4r6r<r=r>r?r@rAr:r0r0r0r1r)<s          r)c @seZdZdZddddddddddd ZddZeddd Zd d Zd d Z ddZ ddZ ddZ ddZ ejdZddZddZddZddZdd ZdS)!r#zThis finds packages. This is meant to match easy_install's technique for looking for packages, by reading pages and looking for appropriate links. FNc  Csk|dkrtdg|_xQ|D]I} | jdrat| } tjj| ra| } |jj| q(W||_g|_ t |_ |pt t t |_ dd|r|ngD|_||_||_||_td| d|d| d | |_tsgxLtj|j|jD]2} tj| }|jd kr1tjd Pq1WdS) aCreate 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. Nz>PackageFinder() missing 1 required keyword argument: 'session'~cSsg|]}d|dfqS)r%r0).0hostr0r0r1 s z*PackageFinder.__init__..versionsplatformabiimplr$zipip is configured with locations that require TLS/SSL, however the ssl module in Python is not available.) TypeError find_links startswithr ospathexistsappend index_urlsdependency_linksset logged_linksr!format_controlsecure_originsallow_all_prereleasesprocess_dependency_linkssessionr valid_tagsr itertoolschain urllib_parseurlparseschemeloggerwarning)r/rQrWr] trusted_hostsr^r_r[rMrLrNimplementationlinknew_linkparsedr0r0r1r2ls>            zPackageFinder.__init__cCs-|jr)tjdt|jj|dS)NzXDependency Links processing has been deprecated and will be removed in a future release.)r^warningswarnr rXextend)r/linksr0r0r1add_dependency_linkss  z"PackageFinder.add_dependency_linkscsXggfdd}x*|D]"}tjj|}|jd}|s[|r|rj|}n t|}tjj|r|rtjj|}xFtj|D]}|tjj||qWq|rj |qJtjj |r ||qJt j d|q(t |r:j |q(t j d|q(WfS)zt Sort locations into "files" (archives) and "urls", and return a pair of lists (files,urls) csLt|}tj|ddddkr;j|n j|dS)NstrictFrz text/html)r mimetypes guess_typerV)rTurl)filesurlsr0r1 sort_paths z0PackageFinder._sort_locations..sort_pathzfile: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.)rSrTrUrRrisdirrealpathlistdirjoinrVisfilerfrgr) locations expand_dirrxru is_local_path is_file_urlrTitemr0)rvrwr1_sort_locationss8         zPackageFinder._sort_locationscCs|t|j}|jjrht|jj}|j|jsRtd|j|j|j }n| }|j |fS)a[ Function used to generate link sort key for link tuples. The greater the return value, the more preferred it is. If not finding wheels, then sorted by version only. If finding wheels, then the sort order is by version, then: 1. existing installs 2. wheels ordered via Wheel.support_index_min(self.valid_tags) 3. source archives Note: it was considered to embed this logic into the Link comparison operators, but then different sdist links with the same version, would have to be considered equal zB%s is not a supported wheel for this platform. It can't be sorted.) lenr`r-is_wheelrfilename supportedrsupport_index_minr,)r/ candidate support_numwheelprir0r0r1_candidate_sort_keys   z!PackageFinder._candidate_sort_keyc Cstjt|}|j|j|jf}|djddd }x]t|jD]N}||dkr~|ddkr~qUyt j t |dt j s|ddkr|dn|djd}t jt |dt j r|dn|djd}WnOtk r[|drW|dj|djkrW|ddkrWwUYnX||krkqU|d|dkr|ddkr|ddk rqUdSW|jd|j|jd S) Nr+r%utf8TzThe repository located at %s is not a trusted or secure host and is being ignored. If this repository is available via HTTPS it is recommended to use HTTPS instead, otherwise you may silence this warning and allow it anyways with '--trusted-host %s'.F)rcrdstrrehostnameportrsplitSECURE_ORIGINSr\r ip_addressrBr text_typedecode ip_network ValueErrorlowerrg) r/rfr-rloriginprotocol secure_originaddrnetworkr0r0r1_validate_secure_origins>       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)N/) posixpathr|rcquoterendswith)ruloc) project_namer0r1mkurl_pypi_urlhs  z?PackageFinder._get_index_urls_locations..mkurl_pypi_urlcsg|]}|qSr0r0)rIru)rr0r1rKus z;PackageFinder._get_index_urls_locations..)rW)r/rr0)rrr1_get_index_urls_locationsas z'PackageFinder._get_index_urls_locationsc sfj|}j|\}}jjdd\}}jj\}}ddtj|||D} fddtjdd|Ddd|Dd d|DD} tjd t| |x| D]} tjd | qWt |} t j | } t || | }j d djD|}g}xZj| |D]F}tjd |jt!|jj |j|WdQRXqpWj ddjD|}|rtjddjdd|Dj | |}|rV|jddtjddjdd|D||||S)aFind all available InstallationCandidate for project_name This checks index_urls, find_links and dependency_links. All versions found are returned as an InstallationCandidate list. See _link_package_versions for details on which files are accepted rTcss|]}t|VqdS)N)Link)rIrur0r0r1 sz4PackageFinder.find_all_candidates..cs(g|]}jt|r|qSr0)rrf)rIrj)r/r0r1rKs z5PackageFinder.find_all_candidates..css|]}t|VqdS)N)r)rIrur0r0r1rscss|]}t|VqdS)N)r)rIrur0r0r1rscss|]}t|VqdS)N)r)rIrur0r0r1rsz,%d location(s) to search for versions of %s:z* %scss|]}t|dVqdS)z-fN)r)rIrur0r0r1rszAnalyzing links from page %sNcss|]}t|VqdS)N)r)rIrur0r0r1rszdependency_links found: %sz, cSsg|]}|jjqSr0)r-ru)rIr,r0r0r1rKs reversezLocal files found: %scSs"g|]}t|jjqSr0)rr-ru)rIrr0r0r1rKs )rrrQrXrarbrfdebugrrfmt_ctl_formatsr[Search_package_versions _get_pagesrur rorpr|sort)r/rindex_locationsindex_file_loc index_url_loc fl_file_loc fl_url_loc dep_file_loc dep_url_locfile_locations url_locationsr-canonical_nameformatssearchfind_links_versions page_versionspagedependency_versions file_versionsr0)r/r1find_all_candidateswsX     !  z!PackageFinder.find_all_candidatescs|j|j}t|jjdd|Dd|jrC|jndfdd|D}|rt|d|j}nd}|jdk rt |jj }nd}|dkr|dkrt j d|dj ttd d |Ddt td |d }|rF|dks@|j |krFd }| r|dk r|rrt jd|nt jd||j dS|rt jd|dj tdt pdtt jd|j dj tdt |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 cSsg|]}t|jqSr0)rr,)rIcr0r0r1rKs z2PackageFinder.find_requirement.. prereleasesNcs+g|]!}t|jkr|qSr0)rr,)rIr)compatible_versionsr0r1rKs keyzNCould not find a version that satisfies the requirement %s (from versions: %s)z, css|]}t|jVqdS)N)rr,)rIrr0r0r1rsz1PackageFinder.find_requirement..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)nonez)Using version %s (newest of versions: %s))rnamerY specifierfilterr]maxr satisfied_byr+r,rfcriticalr|sortedrrrr-)r/requpgradeall_candidatesapplicable_candidatesbest_candidateinstalled_versionbest_installedr0)rr1find_requirementsd       zPackageFinder.find_requirementccs]t}xM|D]E}||kr%q|j||j|}|dkrPq|VqWdS)zp Yields (page, page_url) from the given locations, skipping locations that have errors. N)rYadd _get_page)r/r~rseenr-rr0r0r1r-s     zPackageFinder._get_pagesz-py([123]\.?[0-9]?)$cCsngg}}t}xM|D]E}||kr|j||jrU|j|q|j|qW||S)z Returns elements of links in order, non-egg links first, egg links second, while eliminating duplicates )rYr egg_fragmentrV)r/rpeggsno_eggsrrjr0r0r1 _sort_links@s      zPackageFinder._sort_linkscCsOg}xB|j|D]1}|j||}|dk r|j|qW|S)N)r_link_package_versionsrV)r/rprresultrjvr0r0r1rPs  zPackageFinder._package_versionscCs6||jkr2tjd|||jj|dS)NzSkipping link %s; %s)rZrfrr)r/rjreasonr0r0r1_log_skipped_linkXszPackageFinder._log_skipped_linkc Csd}|jr$|j}|j}n_|j\}}|sP|j|ddS|tkrt|j|d|dSd|jkr|tkr|j|d|jdSd|jkr|dkr|j|ddS|tkryt |j }Wn&t k r |j|d dSYnXt |j |jkrT|j|d |jdS|j|jsz|j|d dS|j}d |jkr|tkr|j|d |jdS|st||j|}|dkr|j|d |jdS|jj|}|re|d|j}|jd}|tjddkre|j|ddSyt|j} Wn4tjk rtjd|j |jd} YnX| stjd||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 %srzPython version is incorrectz3Package %s has an invalid Requires-Python entry: %sTz_The package %s is incompatible with the pythonversion in use. Acceptable python versions are:%szFound link %s, version: %s)rextrrr rrsuppliedrTrrrrr canonicalrr`r,egg_info_matches_py_version_rerstartgroupsysrrequires_pythonrInvalidSpecifierrfrr)) r/rjrr,egg_inforrmatch py_versionsupport_this_pythonr0r0r1r]s               z$PackageFinder._link_package_versionscCstj|d|jS)Nr_)HTMLPageget_pager_)r/rjr0r0r1rszPackageFinder._get_page)rErFrG__doc__r2rq staticmethodrrrrrrrrecompilerrrrrrr0r0r0r1r#es(  Q 1  G  S c     Mz([a-z0-9_.]+)-([a-z0-9_.!+-]+)cCs|j|}|s)tjd|dS|dkr[|jd}||jddS|jdj}|jdd}|jd}|j|r|jdt|dSdSdS)axPull the version part out of a string. :param egg_info: The string to parse. E.g. foo-2.1 :param search_name: The name of the package this belongs to. None to infer the name. Note that this cannot unambiguously parse strings like foo-2-2 which might be foo, 2-2 or foo-2, 2. :param link: The link the string came from, for logging on failure. z%Could not parse version from link: %sNr-_) rrfrrindexrreplacerRr)r search_namerj _egg_info_rer full_matchrlook_forr0r0r1rs  rc@seZdZdZdddZddZedddd Zedd d Z ed d Z e ddZ e ddZejdejZddZdS)rz'Represents one page, along with its URLNcCsd}|rGd|krGtj|d\}}d|krG|d}||_tj|jd|dd|_||_||_dS)Nz Content-Typecharsettransport_encodingnamespaceHTMLElementsF)cgi parse_headercontentrrrlruheaders)r/r rur encoding content_typeparamsr0r0r1r2s      zHTMLPage.__init__cCs|jS)N)ru)r/r0r0r1__str__szHTMLPage.__str__TcCs$|dkrtd|j}|jddd}ddlm}xS|jD]H}|jj|rQ|t|dkrQt j d||dSqQWy|r|j }xbt D]Z}|j |r|j|d|} | jjd rPqt j d || dSqWt j d |tj|\}} } } } }|d krtjjtj| r|j d s|d 7}tj|d}t j d||j|ddd ddi}|j|jjdd} | jjd st j d || dS||j|j|j}Wntjk rl}z|j|||WYdd}~Xntk r}z+d|}|j|||dt jWYdd}~Xnjtj k r}z|j|d||WYdd}~Xn,tj!k r|j|d|YnX|SdS)Nz9get_page() missing 1 required keyword argument: 'session'#rr) VcsSupportz+:zCannot look at %s URL %sr_z text/htmlz,Skipping page %s because of Content-Type: %szGetting page %sr'rz index.htmlz# file: URL is directory, getting %sr Acceptz Cache-Controlz max-age=600z Content-Typeunknownz6There was a problem confirming the ssl certificate: %smethzconnection error: %sz timed out)"rPrusplitpip.vcsrschemesrrRrrfrrr r_get_content_typercrdrSrTryurllib_request url2pathnameurljoingetraise_for_statusr r r HTTPError _handle_failrinfoConnectionErrorTimeout)clsrj skip_archivesr_rurrerbad_extrnetlocrTrqueryfragmentrespinstexcrr0r0r1rsp   +  !   %.)zHTMLPage.get_pagecCs)|dkrtj}|d||dS)Nz%Could not fetch URL %s: %s - skipping)rfr)rjrrurr0r0r1r!9s  zHTMLPage._handle_failcCs`tj|\}}}}}|dkr.dS|j|dd}|j|jjddS)z;Get the Content-Type of the given url, using a HEAD requesthttpr$allow_redirectsTz Content-Type)zhttpzhttps)rcurlsplitheadrr r)rur_rer(rTr)r*r+r0r0r1r@s   zHTMLPage._get_content_typecCsTdd|jjdD}|rI|djdrI|djdS|jSdS)NcSs+g|]!}|jddk r|qS)hrefN)r)rIxr0r0r1rKQs z%HTMLPage.base_url..z.//baserr3)rlfindallrru)r/basesr0r0r1base_urlNszHTMLPage.base_urlccsx|jjdD]}}|jdr|jd}|jtj|j|}|jd}|rvt|nd}t||d|VqWdS)zYields all links in the pagez.//ar3zdata-requires-pythonNr) rlr5r clean_linkrcrr7r r)r/anchorr3ru pyrequirer0r0r1rpYszHTMLPage.linksz[^a-z0-9$&+,/:;=?@.#%_\\|-]cCs|jjdd|S)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).cSsdt|jdS)Nz%%%2xr)ordr)rr0r0r1r9msz%HTMLPage.clean_link..) _clean_resub)r/rur0r0r1r8hs zHTMLPage.clean_link)rErFrGrr2r classmethodrrr!rrr7propertyrprrIr<r8r0r0r0r1rs  U  rc@seZdZddddZddZddZdd Zd d Zd d ZddZ ddZ ddZ ddZ e ddZe ddZe ddZe ddZddZe d d!Ze d"d#Zejd$Ze d%d&Zejd'Ze d(d)Zejd*Ze d+d,Ze d-d.Ze d/d0Ze d1d2Ze d3d4Z dS)5rNcCsF|jdrt|}||_||_|r9|nd|_dS)a Object representing a parsed link from https://pypi.python.org/simple/* url: url of the resource pointed to (href of the link) comes_from: instance of HTMLPage where the link was found, or string. requires_python: String containing the `Requires-Python` metadata field, specified in PEP 345. This may be specified by a data-requires-python attribute in the HTML link tag, as described in PEP 503. z\\N)rRrru comes_fromr)r/rurArr0r0r1r2rs    z Link.__init__cCsP|jrd|j}nd}|jr?d|j|j|fSt|jSdS)Nz (requires-python:%s)r/z%s (from %s)%s)rrArur)r/rpr0r0r1rs   z Link.__str__cCsd|S)Nz r0)r/r0r0r1r4sz Link.__repr__cCs#t|tstS|j|jkS)N)rBrrCru)r/r;r0r0r1r>sz Link.__eq__cCs#t|tstS|j|jkS)N)rBrrCru)r/r;r0r0r1rAsz Link.__ne__cCs#t|tstS|j|jkS)N)rBrrCru)r/r;r0r0r1r<sz Link.__lt__cCs#t|tstS|j|jkS)N)rBrrCru)r/r;r0r0r1r=sz Link.__le__cCs#t|tstS|j|jkS)N)rBrrCru)r/r;r0r0r1r@sz Link.__gt__cCs#t|tstS|j|jkS)N)rBrrCru)r/r;r0r0r1r?sz Link.__ge__cCs t|jS)N)r5ru)r/r0r0r1r6sz Link.__hash__cCsktj|j\}}}}}tj|jdp<|}tj|}|sgtd|j|S)NrzURL %r produced no filename)rcr1rurbasenamerstripunquoteAssertionError)r/rr(rTrr0r0r1rs !z Link.filenamecCstj|jdS)Nr)rcr1ru)r/r0r0r1resz Link.schemecCstj|jdS)Nr)rcr1ru)r/r0r0r1r(sz Link.netloccCstjtj|jdS)Nr)rcrEr1ru)r/r0r0r1rTsz Link.pathcCsttj|jjdS)Nr)rrrCrTrD)r/r0r0r1rsz Link.splitextcCs|jdS)Nr)r)r/r0r0r1rszLink.extcCs=tj|j\}}}}}tj||||dfS)N)rcr1ru urlunsplit)r/rer(rTr)r*r0r0r1url_without_fragments!zLink.url_without_fragmentz[#&]egg=([^&]*)cCs,|jj|j}|sdS|jdS)Nr)_egg_fragment_rerrur)r/rr0r0r1rszLink.egg_fragmentz[#&]subdirectory=([^&]*)cCs,|jj|j}|sdS|jdS)Nr)_subdirectory_fragment_rerrur)r/rr0r0r1subdirectory_fragmentszLink.subdirectory_fragmentz2(sha1|sha224|sha384|sha256|sha512|md5)=([a-f0-9]+)cCs,|jj|j}|r(|jdSdS)Nr)_hash_rerrur)r/rr0r0r1r5s z Link.hashcCs,|jj|j}|r(|jdSdS)Nr)rLrrur)r/rr0r0r1 hash_names zLink.hash_namecCs0tj|jjdddjdddS)Nrrr?)rrCrur)r/r0r0r1show_urlsz Link.show_urlcCs |jtkS)N)rr)r/r0r0r1rsz Link.is_wheelcCs*ddlm}|j|jkr&dSdS)z Determines if this points to an actual artifact (e.g. a tarball) or if it points to an "abstract" thing like a path or a VCS location. r)vcsFT)rrPre all_schemes)r/rPr0r0r1 is_artifactszLink.is_artifact)!rErFrGr2rr4r>rAr<r=r@r?r6r?rrer(rTrrrHrrrIrrJrKrLr5rMrOrrRr0r0r0r1rps8           rzno_binary only_binarycCs|jd}x[d|krl|j|j|jd|d|jdd=d|krdSqWxM|D]E}|dkr|jqtt|}|j||j|qtWdS)N,z:all:rz:none:)rclearrrrdiscard)valuetargetr;newrr0r0r1r"s         cCstddg}||jkr1|jdnZ||jkrP|jdn;d|jkro|jdnd|jkr|jdt|S)Nrrz:all:)rY only_binaryrU no_binary frozenset)fmt_ctlrrr0r0r1r-s rcCstd|j|jdS)Nz:all:)r"rZrY)r\r0r0r1fmt_ctl_no_binary:sr]cCs$t|tjdtdddS)Nzf--no-use-wheel is deprecated and will be removed in the future. Please use --no-binary :all: instead. stacklevelr)r]rmrnr )r\r0r0r1fmt_ctl_no_use_wheel?s  r_rzsupplied canonical formats)Qr __future__rloggingr  collectionsrrarrSrrsrrmZpip._vendor.six.moves.urllibrrcrr pip.compatr pip.utilsrrr r r Zpip.utils.deprecationr pip.utils.loggingr pip.utils.packagingrpip.exceptionsrrrr pip.downloadrrrr pip.wheelrrZpip.pep425tagsr pip._vendorrrrZpip._vendor.packaging.versionr+pip._vendor.packaging.utilsrZpip._vendor.packagingrZpip._vendor.requests.exceptionsrZpip._vendor.distlib.compatr __all__r getLoggerrErfobjectr)r#rr@rrrr!r"rr]r_rr0r0r0r1sd         (""     )M