3 ]@sdZddlmZddlZddlZddlmZddlZddlZddl 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;mZ>dddgZ?d3d4d5d6d7d8gZ@ejAeBZCGdd d eDZEGd!ddeDZFe jGd"e jHfd#d$ZIGd%d&d&eDZJGd'd(d(eDZKedd)ZLd*dZMd+d,ZNd-d.ZOd/d0ZPed1d2ZQdS)9z!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) HTTPErrorSSLError)unescape FormatControlfmt_ctl_handle_mutual_exclude PackageFinderhttps* localhost 127.0.0.0/8::1/128filesshc@s\eZdZddZddZddZddZd d Zd d Zd dZ ddZ ddZ ddZ dS)InstallationCandidatecCs,||_t||_||_|j|j|jf|_dS)N)project parse_versionversionlocation_key)selfr-r/r0r3(/tmp/pip-build-8jg9gmni/pip/pip/index.py__init__>s zInstallationCandidate.__init__cCsdj|j|j|jS)Nz,)formatr-r/r0)r2r3r3r4__repr__DszInstallationCandidate.__repr__cCs t|jS)N)hashr1)r2r3r3r4__hash__IszInstallationCandidate.__hash__cCs|j|ddS)NcSs||kS)Nr3)sor3r3r4Msz.InstallationCandidate.__lt__..)_compare)r2otherr3r3r4__lt__LszInstallationCandidate.__lt__cCs|j|ddS)NcSs||kS)Nr3)r:r;r3r3r4r<Psz.InstallationCandidate.__le__..)r=)r2r>r3r3r4__le__OszInstallationCandidate.__le__cCs|j|ddS)NcSs||kS)Nr3)r:r;r3r3r4r<Ssz.InstallationCandidate.__eq__..)r=)r2r>r3r3r4__eq__RszInstallationCandidate.__eq__cCs|j|ddS)NcSs||kS)Nr3)r:r;r3r3r4r<Vsz.InstallationCandidate.__ge__..)r=)r2r>r3r3r4__ge__UszInstallationCandidate.__ge__cCs|j|ddS)NcSs||kS)Nr3)r:r;r3r3r4r<Ysz.InstallationCandidate.__gt__..)r=)r2r>r3r3r4__gt__XszInstallationCandidate.__gt__cCs|j|ddS)NcSs||kS)Nr3)r:r;r3r3r4r<\sz.InstallationCandidate.__ne__..)r=)r2r>r3r3r4__ne__[szInstallationCandidate.__ne__cCst|tstS||j|jS)N) isinstancer,NotImplementedr1)r2r>methodr3r3r4r=^s zInstallationCandidate._compareN) __name__ __module__ __qualname__r5r7r9r?r@rArBrCrDr=r3r3r3r4r,<sr,c @seZdZdZd!ddZddZed"dd 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 Cs|dkrtdg|_x:|D]2} | jdrBt| } tjj| rB| } |jj| qW||_g|_ t |_ |pvt t t |_ dd|r|ngD|_||_||_||_t| || | d|_tsx8tj|j|jD]$} tj| }|jdkrtjdPqWdS) 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&r3).0hostr3r3r4 sz*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)r2rTrZr` trusted_hostsrarbr^rPrOrQimplementationlinknew_linkparsedr3r3r4r5ls>       zPackageFinder.__init__cCs"|jrtjdt|jj|dS)NzXDependency Links processing has been deprecated and will be removed in a future release.)rawarningswarnr r[extend)r2linksr3r3r4add_dependency_linkss z"PackageFinder.add_dependency_linkscsggfdd}x|D]}tjj|}|jd}|s>|r|rH|}nt|}tjj|r|rtjj|}x4tj|D]}|tjj||qxWq|rƈj |qtjj |r||qt j d|qt |r܈j |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_typerY)rWurl)filesurlsr3r4 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.)rVrWrXrUrisdirrealpathlistdirjoinrYisfilerirjr) locations expand_dirr{rx is_local_path is_file_urlrWitemr3)ryrzr4_sort_locationss8          zPackageFinder._sort_locationscCsXt|j}|jjrHt|jj}|j|js8td|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.) lenrcr0is_wheelrfilename supportedrsupport_index_minr/)r2 candidate support_numwheelprir3r3r4_candidate_sort_keys    z!PackageFinder._candidate_sort_keyc 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+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)rfrgstrrhhostnameportrsplitSECURE_ORIGINSr_r ip_addressrEr text_typedecode ip_network ValueErrorlowerrj) r2rir0rooriginprotocol secure_originaddrnetworkr3r3r4_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/) posixpathrrfquoterendswith)rxloc) project_namer3r4mkurl_pypi_urlhs  z?PackageFinder._get_index_urls_locations..mkurl_pypi_urlcsg|] }|qSr3r3)rLrx)rr3r4rNusz;PackageFinder._get_index_urls_locations..)rZ)r2rr3)rrr4_get_index_urls_locationsas z'PackageFinder._get_index_urls_locationsc sj|}j|\}}jjdd\}}jj\}}ddtj|||D} fddtjdd|Ddd|Dd d|DD} tjd t| |x| D]} tjd | qWt |} t j | } t || | }j d djD|}g}xJj| |D]:}tjd |jt|jj |j|WdQRXqWj ddjD|}|r|tjddjdd|Dj | |}|r|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 T)rcss|]}t|VqdS)N)Link)rLrxr3r3r4 sz4PackageFinder.find_all_candidates..csg|]}jt|r|qSr3)rri)rLrm)r2r3r4rNsz5PackageFinder.find_all_candidates..css|]}t|VqdS)N)r)rLrxr3r3r4rscss|]}t|VqdS)N)r)rLrxr3r3r4rscss|]}t|VqdS)N)r)rLrxr3r3r4rsz,%d location(s) to search for versions of %s:z* %scss|]}t|dVqdS)z-fN)r)rLrxr3r3r4rszAnalyzing links from page %sNcss|]}t|VqdS)N)r)rLrxr3r3r4rszdependency_links found: %sz, cSsg|] }|jjqSr3)r0rx)rLr/r3r3r4rNs)reversezLocal files found: %scSsg|]}t|jjqSr3)rr0rx)rLrr3r3r4rNs)rrrTr[rdreridebugrrfmt_ctl_formatsr^Search_package_versions _get_pagesrxr rrrsrsort)r2rindex_locationsindex_file_loc index_url_loc fl_file_loc fl_url_loc dep_file_loc dep_url_locfile_locations url_locationsr0canonical_nameformatssearchfind_links_versions page_versionspagedependency_versions file_versionsr3)r2r4find_all_candidateswsX             z!PackageFinder.find_all_candidatescsh|j|j}t|jjdd|D|jr,|jnddfdd|D}|r\t||jd}nd}|jdk rxt |jj }nd}|dkr|dkrt j d|dj ttd d |Dt dtd |d }|r|dks|j |krd }| o|dk r|rt jd|nt jd||j dS|rDt jd|dj tt dp.N) prereleasescsg|]}t|jkr|qSr3)rr/)rLr)compatible_versionsr3r4rNs)keyzNCould not find a version that satisfies the requirement %s (from versions: %s)z, css|]}t|jVqdS)N)rr/)rLrr3r3r4rsz1PackageFinder.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))rnamer\ specifierfilterr`maxr satisfied_byr.r/ricriticalrsortedrrrr0)r2requpgradeall_candidatesapplicable_candidatesbest_candidateinstalled_versionbest_installedr3)rr4find_requirementsd       zPackageFinder.find_requirementccsFt}x:|D]2}||krq |j||j|}|dkr8q |Vq WdS)zp Yields (page, page_url) from the given locations, skipping locations that have errors. N)r\add _get_page)r2rrseenr0rr3r3r4r-s   zPackageFinder._get_pagesz-py([123]\.?[0-9]?)$cCsTgg}}t}x:|D]2}||kr|j||jr>|j|q|j|qW||S)z Returns elements of links in order, non-egg links first, egg links second, while eliminating duplicates )r\r egg_fragmentrY)r2rseggsno_eggsrrmr3r3r4 _sort_links@s    zPackageFinder._sort_linkscCs:g}x0|j|D]"}|j||}|dk r|j|qW|S)N)r_link_package_versionsrY)r2rsrresultrmvr3r3r4rPs  zPackageFinder._package_versionscCs(||jkr$tjd|||jj|dS)NzSkipping link %s; %s)r]rirr)r2rmreasonr3r3r4_log_skipped_linkXs zPackageFinder._log_skipped_linkc CsJd}|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|j|js |j|d dS|j}d |jkrR|tkrR|j|d |jdS|sft||j|}|dkr|j|d |jdS|jj|}|r|d|j}|jd}|tjddkr|j|ddSyt|j} Wn.tjk rtjd|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 %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 rrsuppliedrWrrrrr canonicalrrcr/egg_info_matches_py_version_rerstartgroupsysrrequires_pythonrInvalidSpecifierrirr,) r2rmrr/egg_inforrmatch py_versionsupport_this_pythonr3r3r4r]s             z$PackageFinder._link_package_versionscCstj||jdS)N)rb)HTMLPageget_pagerb)r2rmr3r3r4rszPackageFinder._get_page) FNFNNNNNN)F)rHrIrJ__doc__r5rt staticmethodrrrrrrrrecompilerrrrrrr3r3r3r4r$es( Q  1GSc Mz([a-z0-9_.]+)-([a-z0-9_.!+-]+)cCs|j|}|stjd|dS|dkrB|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-_) rrirrindexrreplacerUr)r search_namerm _egg_info_rer full_matchrlook_forr3r3r4rs      rc@sxeZdZdZdddZddZeddd Zedd d Z ed d Z e ddZ e ddZejdejZddZdS)rz'Represents one page, along with its URLNcCs\d}|r2d|kr2tj|d\}}d|kr2|d}||_tj|j|dd|_||_||_dS)Nz Content-TypecharsetF)transport_encodingnamespaceHTMLElements)cgi parse_headercontentrrrorxheaders)r2rrxrencoding content_typeparamsr3r3r4r5s  zHTMLPage.__init__cCs|jS)N)rx)r2r3r3r4__str__szHTMLPage.__str__TcCsj|dkrtd|j}|jddd}ddlm}x>|jD]4}|jj|r:|t|dkr:t j d||dSq:Wy"|r|j }xHt D]@}|j |r|j||d} | jjd rPqt j d || dSqWt j d |tj|\}} } } } }|d kr6tjjtj| r6|j d s|d 7}tj|d}t j d||j|d ddd}|j|jjdd} | jjd st j d || dS||j|j|j}Wntk r}z|j|||WYdd}~Xntk r}z"d|}|j|||t jdWYdd}~Xn`tj 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 %s)rbz text/htmlz,Skipping page %s because of Content-Type: %szGetting page %sr*rz index.htmlz# file: URL is directory, getting %sz max-age=600)Acceptz Cache-Control)rz Content-Typeunknownz6There was a problem confirming the ssl certificate: %s)methzconnection error: %sz timed out)"rSrxsplitpip.vcsrschemesrrUrrirrr r_get_content_typerfrgrVrWr|urllib_request url2pathnameurljoingetraise_for_statusrrr _handle_failr inforConnectionErrorTimeout)clsrm skip_archivesrbrxrrhrbad_extrnetlocrWrqueryfragmentrespinstexcrr3r3r4rsp           $"zHTMLPage.get_pagecCs|dkrtj}|d||dS)Nz%Could not fetch URL %s: %s - skipping)rir)rmrrxrr3r3r4r#9szHTMLPage._handle_failcCsDtj|\}}}}}|dkr dS|j|dd}|j|jjddS)z;Get the Content-Type of the given url, using a HEAD requesthttpr%T)allow_redirectsz Content-Type)r0r%)rfurlsplitheadr"rr!)rxrbrhr*rWr+r,r-r3r3r4r@s zHTMLPage._get_content_typecCs@dd|jjdD}|r6|djdr6|djdS|jSdS)NcSsg|]}|jddk r|qS)hrefN)r!)rLxr3r3r4rNQsz%HTMLPage.base_url..z.//baserr5)rofindallr!rx)r2basesr3r3r4base_urlNszHTMLPage.base_urlccslxf|jjdD]V}|jdr|jd}|jtj|j|}|jd}|rPt|nd}t|||dVqWdS)zYields all links in the pagez.//ar5zdata-requires-pythonN)r) ror7r! clean_linkrfr r9r!r)r2anchorr5rx pyrequirer3r3r4rsYs   zHTMLPage.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)rr3r3r4r<msz%HTMLPage.clean_link..) _clean_resub)r2rxr3r3r4r:hszHTMLPage.clean_link)N)TN)N)rHrIrJrr5r classmethodrrr#rrr9propertyrsrrIr>r:r3r3r3r4rs  U   rc@s eZdZd5ddZddZddZdd 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)6rNcCs0|jdrt|}||_||_|r&|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)rUrrx comes_fromr)r2rxrCrr3r3r4r5rs  z Link.__init__cCs<|jrd|j}nd}|jr.d|j|j|fSt|jSdS)Nz (requires-python:%s)r1z%s (from %s)%s)rrCrxr)r2rpr3r3r4rs  z Link.__str__cCsd|S)Nz r3)r2r3r3r4r7sz Link.__repr__cCst|tstS|j|jkS)N)rErrFrx)r2r>r3r3r4rAs z Link.__eq__cCst|tstS|j|jkS)N)rErrFrx)r2r>r3r3r4rDs z Link.__ne__cCst|tstS|j|jkS)N)rErrFrx)r2r>r3r3r4r?s z Link.__lt__cCst|tstS|j|jkS)N)rErrFrx)r2r>r3r3r4r@s z Link.__le__cCst|tstS|j|jkS)N)rErrFrx)r2r>r3r3r4rCs z Link.__gt__cCst|tstS|j|jkS)N)rErrFrx)r2r>r3r3r4rBs z Link.__ge__cCs t|jS)N)r8rx)r2r3r3r4r9sz Link.__hash__cCsJtj|j\}}}}}tj|jdp(|}tj|}|sFtd|j|S)NrzURL %r produced no filename)rfr3rxrbasenamerstripunquoteAssertionError)r2rr*rWrr3r3r4rs  z Link.filenamecCstj|jdS)Nr)rfr3rx)r2r3r3r4rhsz Link.schemecCstj|jdS)Nr)rfr3rx)r2r3r3r4r*sz Link.netloccCstjtj|jdS)Nr)rfrGr3rx)r2r3r3r4rWsz Link.pathcCsttj|jjdS)Nr)rrrErWrF)r2r3r3r4rsz Link.splitextcCs |jdS)Nr)r)r2r3r3r4rszLink.extcCs*tj|j\}}}}}tj||||dfS)N)rfr3rx urlunsplit)r2rhr*rWr+r,r3r3r4url_without_fragmentszLink.url_without_fragmentz[#&]egg=([^&]*)cCs |jj|j}|sdS|jdS)Nr)_egg_fragment_rerrxr)r2rr3r3r4rszLink.egg_fragmentz[#&]subdirectory=([^&]*)cCs |jj|j}|sdS|jdS)Nr)_subdirectory_fragment_rerrxr)r2rr3r3r4subdirectory_fragmentszLink.subdirectory_fragmentz2(sha1|sha224|sha384|sha256|sha512|md5)=([a-f0-9]+)cCs |jj|j}|r|jdSdS)Nr)_hash_rerrxr)r2rr3r3r4r8s z Link.hashcCs |jj|j}|r|jdSdS)Nr)rNrrxr)r2rr3r3r4 hash_names zLink.hash_namecCs$tj|jjdddjdddS)Nrrr?)rrErxr)r2r3r3r4show_urlsz Link.show_urlcCs |jtkS)N)rr)r2r3r3r4rsz Link.is_wheelcCs ddlm}|j|jkrdSdS)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)rrRrh all_schemes)r2rRr3r3r4 is_artifacts  zLink.is_artifact)NN)!rHrIrJr5rr7rArDr?r@rCrBr9rArrhr*rWrrrJrrrKrrLrMrNr8rOrQrrTr3r3r3r4rps8                rzno_binary only_binarycCs|jd}xFd|krP|j|j|jd|d|jdd=d|kr dSq Wx:|D]2}|dkrn|jqXt|}|j||j|qXWdS)N,z:all:rz:none:)rclearrrrdiscard)valuetargetr>newrr3r3r4r#s     cCsjtddg}||jkr"|jdn@||jkr8|jdn*d|jkrN|jdnd|jkrb|jdt|S)Nrrz:all:)r\ only_binaryrW no_binary frozenset)fmt_ctlrrr3r3r4r-s         rcCstd|j|jdS)Nz:all:)r#r\r[)r^r3r3r4fmt_ctl_no_binary:sr_cCst|tjdtdddS)Nzf--no-use-wheel is deprecated and will be removed in the future. Please use --no-binary :all: instead.r) stacklevel)r_rprqr )r^r3r3r4fmt_ctl_no_use_wheel?s rarzsupplied canonical formats)r%r&r&)r&r'r&)r&r(r&)r&r)r&)r*r&N)r+r&r&)Rr __future__rloggingr  collectionsrrdrrVrrvrrpZpip._vendor.six.moves.urllibrrfrr 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.exceptionsrr Zpip._vendor.distlib.compatr!__all__r getLoggerrHriobjectr,r$rrBrrrr"r#rr_rarr3r3r3r4sl               )O&!