o EcY&@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)Zsha1Zsha224Zsha384Zsha256Zsha512Zmd5c 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)keyZdefining_class) startswithrurllibparseurlsplitrrrrrsuper__init__rr)selfrrrrr __class__L/opt/alt/python310/lib/python3.10/site-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"Zrpr%r%r&__str__Vsz Link.__str__cCs d|dS)Nzr%r"r%r%r&__repr__bs z Link.__repr__cCs|jSN)rr-r%r%r&reszLink.urlcCs<|jd}t|}|st|j\}}|Stj|}|SN/) pathrstrip posixpathbasenamer netlocrrunquote)r"r2namer6Z user_passr%r%r&filenameis   z Link.filenamecCs t|jSr/)rrr-r%r%r& file_pathw zLink.file_pathcC|jjSr/)rschemer-r%r%r&r={sz Link.schemecCr<)z4 This can contain auth information. )rr6r-r%r%r&r6sz Link.netloccCstj|jjSr/)rrr7rr2r-r%r%r&r2z Link.pathcCstt|jdSr0)r r4r5r2r3r-r%r%r&r sz Link.splitextcCs |dSN)r r-r%r%r&exts zLink.extcCs&|j\}}}}}tj||||dfS)Nr()rrr urlunsplit)r"r=r6r2queryfragmentr%r%r&url_without_fragmentszLink.url_without_fragmentz[#&]egg=([^&]*)cC |j|j}|s dS|dSr?)_egg_fragment_researchrgroupr"matchr%r%r& egg_fragment zLink.egg_fragmentz[#&]subdirectory=([^&]*)cCrFr?)_subdirectory_fragment_rerHrrIrJr%r%r&subdirectory_fragmentrMzLink.subdirectory_fragmentz({choices})=([a-f0-9]+)|)choicescC |j|j}|r|dSdS)N_hash_rerHrrIrJr%r%r&hash z Link.hashcCrRr?rTrJr%r%r& hash_namerWzLink.hash_namecCs$t|jddddddS)N#r@r?)r4r5rsplitr-r%r%r&show_urls$z Link.show_urlcCs |jdkS)Nfile)r=r-r%r%r&is_filer;z Link.is_filecCs|jo tj|jSr/)r^osr2isdirr:r-r%r%r&is_existing_dirszLink.is_existing_dircCs |jtkSr/)rAr r-r%r%r&is_wheelr;z Link.is_wheelcCsddlm}|j|jvS)Nr)vcs)Zpip._internal.vcsrcr=Z all_schemes)r"rcr%r%r&is_vcss  z Link.is_vcscC |jduSr/)rr-r%r%r& is_yankedr;zLink.is_yankedcCrer/)rXr-r%r%r&has_hashr;z Link.has_hashhashescCs$|dus|js dS|j|j|jdS)zG Return True if the link has a hash and it is allowed. NF)Z hex_digest)rgis_hash_allowedrXrV)r"rhr%r%r&riszLink.is_hash_allowed)NNNT)-__name__ __module__ __qualname____doc__ __slots__r*rrboolr!r+r.propertyrr9r:r=r6r2rr rArErecompilerGrLrNrOr)join_SUPPORTED_HASHESrUrVrXr\r^rarbrdrfrgr ri __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. parsedrC subdirectoryrhN) rjrkrlrmrr SplitResult__annotations__rr*rr%r%r%r&rvs  rvlinkrc 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@r@r]Z localhostZeggzIgnoring egg= fragment in %srxrr(cs"i|] }|vr||dqS)rr%).0krDr%r& s"z_clean_link..)r6rCrD)rwrCrxrh)rr6rsplitr=rrparse_qsrDloggerdebug IndexErrorKeyErrorrtrv_replacerC)r{rwr6rxrhr%rr& _clean_links&  r)maxsizelink1link2cCst|t|kSr/)r)rrr%r%r&links_equivalentr>r)( functoolsZloggingr_r4rq urllib.parsertypingrrrrrrrZpip._internal.utils.filetypesr Zpip._internal.utils.hashesr Zpip._internal.utils.miscr r r Zpip._internal.utils.modelsrZpip._internal.utils.urlsrrZpip._internal.index.collectorrZ getLoggerrjrrtrrvr lru_cacherorr%r%r%r&s,$     I