3 . g@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;ddld3d4d5d6d7d8gZ?ej@eAZBGdd d eCZDGd!ddeCZEe jFd"e jGfd#d$ZHGd%d&d&eCZIGd'd(d(eCZJedd)ZKd*dZLd+d,ZMd-d.ZNd/d0ZOed1d2ZPdS)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)SSLError)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.r/r2/usr/lib/python3.6/index.py__init__>s zInstallationCandidate.__init__cCsdj|j|j|jS)Nz,)formatr,r.r/)r1r2r2r3__repr__DszInstallationCandidate.__repr__cCs t|jS)N)hashr0)r1r2r2r3__hash__IszInstallationCandidate.__hash__cCs|j|ddS)NcSs||kS)Nr2)sor2r2r3Msz.InstallationCandidate.__lt__..)_compare)r1otherr2r2r3__lt__LszInstallationCandidate.__lt__cCs|j|ddS)NcSs||kS)Nr2)r9r:r2r2r3r;Psz.InstallationCandidate.__le__..)r<)r1r=r2r2r3__le__OszInstallationCandidate.__le__cCs|j|ddS)NcSs||kS)Nr2)r9r:r2r2r3r;Ssz.InstallationCandidate.__eq__..)r<)r1r=r2r2r3__eq__RszInstallationCandidate.__eq__cCs|j|ddS)NcSs||kS)Nr2)r9r:r2r2r3r;Vsz.InstallationCandidate.__ge__..)r<)r1r=r2r2r3__ge__UszInstallationCandidate.__ge__cCs|j|ddS)NcSs||kS)Nr2)r9r:r2r2r3r;Ysz.InstallationCandidate.__gt__..)r<)r1r=r2r2r3__gt__XszInstallationCandidate.__gt__cCs|j|ddS)NcSs||kS)Nr2)r9r:r2r2r3r;\sz.InstallationCandidate.__ne__..)r<)r1r=r2r2r3__ne__[szInstallationCandidate.__ne__cCst|tstS||j|jS)N) isinstancer+NotImplementedr0)r1r=methodr2r2r3r<^s zInstallationCandidate._compareN) __name__ __module__ __qualname__r4r6r8r>r?r@rArBrCr<r2r2r2r3r+<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%r2).0hostr2r2r3 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)r1rSrYr_Z trusted_hostsr`rar]rOrNrPimplementationlinkZnew_linkparsedr2r2r3r4ls>       zPackageFinder.__init__cCs"|jrtjdt|jj|dS)NzXDependency Links processing has been deprecated and will be removed in a future release.)r`warningswarnr rZextend)r1linksr2r2r3add_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 mimetypesZ guess_typerX)rVurl)filesurlsr2r3 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.)rUrVrWrTrisdirrealpathlistdirjoinrXisfilerhrir) locations expand_dirrwrtZ is_local_pathZ is_file_urlrVitemr2)rurvr3_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.) lenrbr/is_wheelrfilename supportedrZsupport_index_minr.)r1 candidateZ support_numwheelZprir2r2r3_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)rerfstrrgZhostnameZportrsplitSECURE_ORIGINSr^rZ ip_addressrDrZ text_typedecodeZ ip_network ValueErrorlowerri) r1rhr/rloriginZprotocolZ secure_originZaddrZnetworkr2r2r3_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{reZquoterendswith)rtloc) project_namer2r3mkurl_pypi_urlhs  z?PackageFinder._get_index_urls_locations..mkurl_pypi_urlcsg|] }|qSr2r2)rKrt)rr2r3rMusz;PackageFinder._get_index_urls_locations..)rY)r1rr2)rrr3_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)r~css|]}t|VqdS)N)Link)rKrtr2r2r3 sz4PackageFinder.find_all_candidates..csg|]}jt|r|qSr2)rrh)rKrk)r1r2r3rMsz5PackageFinder.find_all_candidates..css|]}t|VqdS)N)r)rKrtr2r2r3rscss|]}t|VqdS)N)r)rKrtr2r2r3rscss|]}t|VqdS)N)r)rKrtr2r2r3rsz,%d location(s) to search for versions of %s:z* %scss|]}t|dVqdS)z-fN)r)rKrtr2r2r3rszAnalyzing links from page %sNcss|]}t|VqdS)N)r)rKrtr2r2r3rszdependency_links found: %sz, cSsg|] }|jjqSr2)r/rt)rKr.r2r2r3rMs)reversezLocal files found: %scSsg|]}t|jjqSr2)rr/rt)rKrr2r2r3rMs)rrrSrZrcrdrhdebugrrfmt_ctl_formatsr]Search_package_versions _get_pagesrtr rorpr{sort)r1rZindex_locationsZindex_file_locZ index_url_locZ fl_file_locZ fl_url_locZ dep_file_locZ dep_url_locZfile_locationsZ url_locationsr/canonical_nameformatssearchZfind_links_versionsZ page_versionspageZdependency_versionsZ file_versionsr2)r1r3find_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)Z prereleasescsg|]}t|jkr|qSr2)rr.)rKr)compatible_versionsr2r3rMs)keyzNCould not find a version that satisfies the requirement %s (from versions: %s)z, css|]}t|jVqdS)N)rr.)rKrr2r2r3rsz1PackageFinder.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)Znonez)Using version %s (newest of versions: %s))rnamer[Z specifierfilterr_maxrZ satisfied_byr-r.rhZcriticalr{sortedrrrr/)r1ZreqZupgradeZall_candidatesZapplicable_candidatesZbest_candidateZinstalled_versionZbest_installedr2)rr3find_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)r1r}rseenr/rr2r2r3r-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_fragmentrX)r1rpZeggsZno_eggsrrkr2r2r3 _sort_links@s    zPackageFinder._sort_linkscCs:g}x0|j|D]"}|j||}|dk r|j|qW|S)N)r_link_package_versionsrX)r1rprresultrkvr2r2r3rPs  zPackageFinder._package_versionscCs(||jkr$tjd|||jj|dS)NzSkipping link %s; %s)r\rhrr)r1rkreasonr2r2r3_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 %sZmacosx10z.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 rrZsuppliedrVrrrrrZ canonicalrrbr.egg_info_matches_py_version_rerstartgroupsysrrequires_pythonrZInvalidSpecifierrhrr+) r1rkrr.egg_inforrmatch py_versionZsupport_this_pythonr2r2r3r]s             z$PackageFinder._link_package_versionscCstj||jdS)N)ra)HTMLPageget_pagera)r1rkr2r2r3rszPackageFinder._get_page) FNFNNNNNN)F)rGrHrI__doc__r4rq staticmethodrrrrrrrrecompilerrrrrrr2r2r2r3r#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-_) rrhrrindexrreplacerTr)rZ search_namerkZ _egg_info_rerZ full_matchrZlook_forr2r2r3rs      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)Ztransport_encodingZnamespaceHTMLElements)cgiZ parse_headercontentrrrlrtheaders)r1rrtrencoding content_typeparamsr2r2r3r4s  zHTMLPage.__init__cCs|jS)N)rt)r1r2r2r3__str__szHTMLPage.__str__TcCsl|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}Wntjk r}z|j|||WYdd}~Xntk r}z"d|}|j|||t jdWYdd}~Xn`tj k r>}z|j|d||WYdd}~Xn*tj!k rb|j|d|YnX|SdS)Nz9get_page() missing 1 required keyword argument: 'session'#rr) VcsSupportz+:zCannot look at %s URL %s)raz text/htmlz,Skipping page %s because of Content-Type: %szGetting page %sr)rz index.htmlz# file: URL is directory, getting %sz max-age=600)ZAcceptz Cache-Control)rz Content-Typeunknownz6There was a problem confirming the ssl certificate: %s)methzconnection error: %sz timed out)"rRrtsplitpip.vcsrZschemesrrTrrhrrr r_get_content_typererfrUrVrxurllib_requestZ url2pathnameurljoingetraise_for_statusrrrZ HTTPError _handle_failrinfoConnectionErrorZTimeout)clsrkZ skip_archivesrartrrgrZbad_extrnetlocrVrqueryfragmentrespZinstexcrr2r2r3rsp           $"zHTMLPage.get_pagecCs|dkrtj}|d||dS)Nz%Could not fetch URL %s: %s - skipping)rhr)rkrrtrr2r2r3r9szHTMLPage._handle_failcCsDtj|\}}}}}|dkr dS|j|dd}|j|jjddS)z;Get the Content-Type of the given url, using a HEAD requesthttpr$T)Zallow_redirectsz Content-Type)rr$)reurlsplitheadrrr)rtrargrrVrrrr2r2r3r@s zHTMLPage._get_content_typecCs@dd|jjdD}|r6|djdr6|djdS|jSdS)NcSsg|]}|jddk r|qS)hrefN)r)rKxr2r2r3rMQsz%HTMLPage.base_url..z.//baserr)rlfindallrrt)r1basesr2r2r3base_urlNszHTMLPage.base_urlccslxf|jjdD]V}|jdr|jd}|jtj|j|}|jd}|rPt|nd}t|||dVqWdS)zYields all links in the pagez.//arzdata-requires-pythonN)r) rlrr clean_linkrerrr r)r1ZanchorrrtZ pyrequirer2r2r3rpYs   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)rr2r2r3r;msz%HTMLPage.clean_link..) _clean_resub)r1rtr2r2r3rhszHTMLPage.clean_link)N)TN)N)rGrHrIrr4r classmethodrrrrrrpropertyrprrIrrr2r2r2r3rs  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)rTrrt comes_fromr)r1rtrrr2r2r3r4rs  z Link.__init__cCs<|jrd|j}nd}|jr.d|j|j|fSt|jSdS)Nz (requires-python:%s)rz%s (from %s)%s)rrrtr)r1Zrpr2r2r3rs  z Link.__str__cCsd|S)Nz r2)r1r2r2r3r6sz Link.__repr__cCst|tstS|j|jkS)N)rDrrErt)r1r=r2r2r3r@s z Link.__eq__cCst|tstS|j|jkS)N)rDrrErt)r1r=r2r2r3rCs z Link.__ne__cCst|tstS|j|jkS)N)rDrrErt)r1r=r2r2r3r>s z Link.__lt__cCst|tstS|j|jkS)N)rDrrErt)r1r=r2r2r3r?s z Link.__le__cCst|tstS|j|jkS)N)rDrrErt)r1r=r2r2r3rBs z Link.__gt__cCst|tstS|j|jkS)N)rDrrErt)r1r=r2r2r3rAs z Link.__ge__cCs t|jS)N)r7rt)r1r2r2r3r8sz Link.__hash__cCsJtj|j\}}}}}tj|jdp(|}tj|}|sFtd|j|S)NrzURL %r produced no filename)rerrtrbasenamerstripunquoteAssertionError)r1rrrVrr2r2r3rs  z Link.filenamecCstj|jdS)Nr)rerrt)r1r2r2r3rgsz Link.schemecCstj|jdS)Nr)rerrt)r1r2r2r3rsz Link.netloccCstjtj|jdS)Nr)rerrrt)r1r2r2r3rVsz Link.pathcCsttj|jjdS)Nr)rrrrVr)r1r2r2r3rsz Link.splitextcCs |jdS)Nr)r)r1r2r2r3rszLink.extcCs*tj|j\}}}}}tj||||dfS)N)rerrtZ urlunsplit)r1rgrrVrrr2r2r3url_without_fragmentszLink.url_without_fragmentz[#&]egg=([^&]*)cCs |jj|j}|sdS|jdS)Nr)_egg_fragment_rerrtr)r1rr2r2r3rszLink.egg_fragmentz[#&]subdirectory=([^&]*)cCs |jj|j}|sdS|jdS)Nr)_subdirectory_fragment_rerrtr)r1rr2r2r3subdirectory_fragmentszLink.subdirectory_fragmentz2(sha1|sha224|sha384|sha256|sha512|md5)=([a-f0-9]+)cCs |jj|j}|r|jdSdS)Nr)_hash_rerrtr)r1rr2r2r3r7s z Link.hashcCs |jj|j}|r|jdSdS)Nr)rrrtr)r1rr2r2r3 hash_names zLink.hash_namecCs$tj|jjdddjdddS)Nrrr?)rrrtr)r1r2r2r3show_urlsz Link.show_urlcCs |jtkS)N)rr)r1r2r2r3rsz 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)rr rgZ all_schemes)r1r r2r2r3 is_artifacts  zLink.is_artifact)NN)!rGrHrIr4rr6r@rCr>r?rBrAr8rrrgrrVrrrrrrrrrrr7r r rr r2r2r2r3rps8                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=newrr2r2r3r"s     cCsjtddg}||jkr"|jdn@||jkr8|jdn*d|jkrN|jdnd|jkrb|jdt|S)Nrrz:all:)r[ only_binaryr no_binary frozenset)fmt_ctlrrr2r2r3r-s         rcCstd|j|jdS)Nz:all:)r"rr)rr2r2r3fmt_ctl_no_binary:srcCst|tjdtdddS)Nzf--no-use-wheel is deprecated and will be removed in the future. Please use --no-binary :all: instead.r) stacklevel)rrmrnr )rr2r2r3fmt_ctl_no_use_wheel?s rrzsupplied canonical formats)r$r%r%)r%r&r%)r%r'r%)r%r(r%)r)r%N)r*r%r%)QrZ __future__rZloggingr collectionsrrcrrUrrsrrmZpip._vendor.six.moves.urllibrrerrZ pip.compatrZ pip.utilsrrr r r Zpip.utils.deprecationr Zpip.utils.loggingr Zpip.utils.packagingrZpip.exceptionsrrrrZ pip.downloadrrrrZ pip.wheelrrZpip.pep425tagsrZ pip._vendorrrrZpip._vendor.packaging.versionr-Zpip._vendor.packaging.utilsrZpip._vendor.packagingrZpip._vendor.requests.exceptionsrZpip._vendor.distlib.compatr __all__rZ getLoggerrGrhobjectr+r#rrrrrr!r"rrrrr2r2r2r3sl                )O&!