o gY&@sddlZddlZddlZddlZddlZddlZddlmZm Z m Z m Z m Z m Z mZddlmZddlmZddlmZmZmZddlmZddlmZmZerVddlmZeeZ d Z!Gd d d eZ"Gd d d e Z#de"de#fddZ$ej%ddde"de"de&fddZ'dS)N) TYPE_CHECKINGDictList NamedTupleOptionalTupleUnion)WHEEL_EXTENSION)Hashes)redact_auth_from_urlsplit_auth_from_netlocsplitext)KeyBasedCompareMixin) path_to_url url_to_path)HTMLPage)sha1sha224sha384sha256sha512md5c s6eZdZdZgdZ    dBdedeeedfdeed eed ed df fd d Z d efddZ d efddZ e d efddZ e d efddZe d efddZe d efddZe d efddZe d efddZd eeeffddZe d efd d!Ze d efd"d#Zed$Ze d eefd%d&Zed'Ze d eefd(d)Zed*jd+ed,Z e d eefd-d.Z!e d eefd/d0Z"e d efd1d2Z#e d efd3d4Z$d efd5d6Z%e d efd7d8Z&e d efd9d:Z'e d efd;d<Z(e d efd=d>Z)d?ee*d efd@dAZ+Z,S)CLinkz:Represents a parsed link from a Package Index's simple URL) _parsed_url_url comes_fromrequires_python yanked_reasoncache_link_parsingNTurlrrrrrreturncsZ|dr t|}tj||_||_||_|r|nd|_||_ t j |t d||_ dS)a :param url: url of the resource pointed to (href of the link) :param comes_from: instance of HTMLPage where the link was found, or string. :param 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. :param yanked_reason: the reason the file has been yanked, if the file has been yanked, or None if the file hasn't been yanked. This is the value of the "data-yanked" attribute, if present, in a simple repository HTML link. If the file has been yanked but no reason was provided, this should be the empty string. See PEP 592 for more information and the specification. :param cache_link_parsing: A flag that is used elsewhere to determine whether resources retrieved from this link should be cached. PyPI index urls should generally have this set to False, for example. z\\N)keydefining_class) startswithrurllibparseurlsplitrrrrrsuper__init__rr)selfrrrrr __class__;/usr/lib/python3/dist-packages/pip/_internal/models/link.pyr((s  z Link.__init__cCsD|jr d|jd}nd}|jrdt|j|j|Stt|jS)Nz (requires-python:)z{} (from {}){})rrformatr rstr)r)rpr,r,r-__str__Vsz Link.__str__cCs d|dS)Nzr,r)r,r,r-__repr__bs z Link.__repr__cCs|jSN)rr5r,r,r-reszLink.urlcCsR|jd}t|}|st|j\}}|Stj|}|s'Jd|j d|S)N/zURL z produced no filename) pathrstrip posixpathbasenamer netlocr$r%unquoter)r)r9namer= user_passr,r,r-filenameis   z Link.filenamecCs t|jSr7)rrr5r,r,r- file_pathw zLink.file_pathcC|jjSr7)rschemer5r,r,r-rE{sz Link.schemecCrD)z4 This can contain auth information. )rr=r5r,r,r-r=sz Link.netloccCstj|jjSr7)r$r%r>rr9r5r,r,r-r9z Link.pathcCstt|jdS)Nr8)r r;r<r9r:r5r,r,r-r sz Link.splitextcCs |dSN)r r5r,r,r-exts zLink.extcCs&|j\}}}}}tj||||dfS)Nr/)rr$r% urlunsplit)r)rEr=r9queryfragmentr,r,r-url_without_fragmentszLink.url_without_fragmentz[#&]egg=([^&]*)cC |j|j}|s dS|dSrG)_egg_fragment_researchrgroupr)matchr,r,r- egg_fragment zLink.egg_fragmentz[#&]subdirectory=([^&]*)cCrNrG)_subdirectory_fragment_rerPrrQrRr,r,r-subdirectory_fragmentrUzLink.subdirectory_fragmentz({choices})=([a-f0-9]+)|)choicescC |j|j}|r|dSdS)N_hash_rerPrrQrRr,r,r-hash z Link.hashcCrZrGr\rRr,r,r- hash_namer_zLink.hash_namecCs$t|jddddddS)N#rHr?)r;r<rsplitr5r,r,r-show_urls$z Link.show_urlcCs |jdkS)Nfile)rEr5r,r,r-is_filerCz Link.is_filecCs|jo tj|jSr7)rfosr9isdirrBr5r,r,r-is_existing_dirszLink.is_existing_dircCs |jtkSr7)rIr r5r,r,r-is_wheelrCz Link.is_wheelcCsddlm}|j|jvS)Nr)vcs)pip._internal.vcsrkrE all_schemes)r)rkr,r,r-is_vcss  z Link.is_vcscC |jduSr7)rr5r,r,r- is_yankedrCzLink.is_yankedcCror7)r`r5r,r,r-has_hashrCz Link.has_hashhashescCs@|dus|js dS|jdusJ|jdusJ|j|j|jdS)zG Return True if the link has a hash and it is allowed. NF) hex_digest)rqr`r^is_hash_allowed)r)rrr,r,r-rts zLink.is_hash_allowed)NNNT)-__name__ __module__ __qualname____doc__ __slots__r1rrboolr(r3r6propertyrrArBrEr=r9rr rIrMrecompilerOrTrVrWr0join_SUPPORTED_HASHESr]r^r`rdrfrirjrnrprqr rt __classcell__r,r,r*r-rs .    rc@sJeZdZUdZejjed<ee e e fed<e ed<ee e fed<dS) _CleanResultaConvert link for equivalency check. This is used in the resolver to check whether two URL-specified requirements likely point to the same distribution and can be considered equivalent. This equivalency logic avoids comparing URLs literally, which can be too strict (e.g. "a=1&b=2" vs "b=2&a=1") and produce conflicts unexpecting to users. Currently this does three things: 1. Drop the basic auth part. This is technically wrong since a server can serve different content based on auth, but if it does that, it is even impossible to guarantee two URLs without auth are equivalent, since the user can input different auth information when prompted. So the practical solution is to assume the auth doesn't affect the response. 2. Parse the query to avoid the ordering issue. Note that ordering under the same key in the query are NOT cleaned; i.e. "a=1&a=2" and "a=2&a=1" are still considered different. 3. Explicitly drop most of the fragment part, except ``subdirectory=`` and hash values, since it should have no impact the downloaded content. Note that this drops the "egg=" part historically used to denote the requested project (and extras), which is wrong in the strictest sense, but too many people are supplying it inconsistently to cause superfluous resolution conflicts, so we choose to also ignore them. parsedrK subdirectoryrrN) rurvrwrxr$r% SplitResult__annotations__rr1rr,r,r,r-rs  rlinkr c s|j}|jddd}|jdkr|sd}tj|jdvr&t d|zdd }Wn t t fy;d }Ynwfd d t D}t |j|d d d tj|j||dS)N@rHre localhosteggzIgnoring egg= fragment in %srrr/cs"i|] }|vr||dqS)rr,).0krLr,r- s"z_clean_link..)r=rKrL)rrKrrr)rr=rsplitrEr$r%parse_qsrLloggerdebug IndexErrorKeyErrorrr_replacerK)rrr=rrrr,rr- _clean_links&  r)maxsizelink1link2cCst|t|kSr7)r)rrr,r,r-links_equivalentrFr)( functoolsloggingrgr;r| urllib.parser$typingrrrrrrrpip._internal.utils.filetypesr pip._internal.utils.hashesr pip._internal.utils.miscr r r pip._internal.utils.modelsrpip._internal.utils.urlsrrpip._internal.index.collectorr getLoggerrurrrrr lru_cacherzrr,r,r,r-s,$     I