U2 HddlmZddlZddlZddlZddlZddlZddlZddlZ ddl m Z ddl m Z ddlmZmZmZddlmZddlmZddlmZdd lmZmZmZmZdd lmZmZerdd l m!Z!ej"e#Z$d Z%e d GddZ&e d GddZ'd-dZ(d.dZ)d.dZ*ej+dej,Z-d/dZ.d0d!Z/d1d#Z0ej1Gd$d%Z2Gd&d'eZ3d2d)Z4ej5d3d,Z6dS)4) annotationsN)Mapping) dataclass) TYPE_CHECKINGAny NamedTuple) deprecated)WHEEL_EXTENSION)Hashes)pairwiseredact_auth_from_urlsplit_auth_from_netlocsplitext) path_to_url url_to_path) IndexContent)sha512sha384sha256sha224sha1md5T)frozenceZdZUdZded<ded<ejddde DZ dd Z e e jddZddZddZddZdS)LinkHashaLinks to content may have embedded hash values. This class parses those. `name` must be any member of `_SUPPORTED_HASHES`. This class can be converted to and from `ArchiveInfo`. While ArchiveInfo intends to be JSON-serializable to conform to PEP 610, this class contains the logic for parsing a hash name and value for correctness, and then checking whether that hash conforms to a schema with `.is_hash_allowed()`.strnamevaluez[#&]({choices})=([^&]*)|c#>K|]}tj|VdSN)reescape).0 hash_names k/builddir/build/BUILD/cloudlinux-venv-1.0.10/venv/lib/python3.11/site-packages/pip/_internal/models/link.py zLinkHash.=s,UUiRYy11UUUUUU)choicesreturnNonec&|jtvsJdSr!)r_SUPPORTED_HASHESselfs r& __post_init__zLinkHash.__post_init__Asy-------r(urlLinkHash | Nonec|j|}|dS|\}}|||S)zGSearch a string for a checksum algorithm name and encoded output value.Nrr)_hash_url_fragment_researchgroups)clsr1matchrrs r&find_hash_url_fragmentzLinkHash.find_hash_url_fragmentDsJ)0055 =4llnn esE****r(dict[str, str]c|j|jiSr!r4r.s r&as_dictzLinkHash.as_dictNs 4:&&r(r c:t|j|jgiS)z@Return a Hashes instance which checks only for the current hash.)r rrr.s r& as_hasheszLinkHash.as_hashesQsty4:,/000r(hashes Hashes | NoneboolcL|dS||j|jS)zI Return True if the current hash is allowed by `hashes`. NF) hex_digest)is_hash_allowedrrr/r@s r&rEzLinkHash.is_hash_allowedUs+ >5%%diDJ%GGGr(Nr*r+)r1rr*r2)r*r;r*r r@rAr*rB)__name__ __module__ __qualname____doc____annotations__r"compileformatjoinr-r5r0 classmethod functoolscacher:r=r?rEr(r&rr(s77IIIJJJ&BJ #))HHUUCTUUUUU *   ...._+++_[+''''1111HHHHHHr(rc&eZdZUdZded<ddZdS) MetadataFilezFInformation about a core metadata file associated with a distribution.dict[str, str] | Noner@r*r+cX|j td|jDsJdSdS)Nc3(K|] }|tvVdSr!r-)r$rs r&r'z-MetadataFile.__post_init__..fs(IITt00IIIIIIr()r@allr.s r&r0zMetadataFile.__post_init__ds= ; "IIT[IIIII I II # " I Ir(NrG)rJrKrLrMrNr0rUr(r&rWrW^sBPP!!!!JJJJJJr(rWr@rXr*cR|dSd|D}|sdS|S)Nc,i|]\}}|tv||SrUr[)r$nvs r& z$supported_hashes..ns) H H Htq!6G1G1Ga1G1G1Gr()itemsr@s r&supported_hashesrdis;~t H Hv||~~ H H HF t Mr(partrcztjtj|S)zP Clean a "part" of a URL path (i.e. after splitting on "@" characters). )urllibparsequoteunquote)res r&_clean_url_path_partrkts* <  fl22488 9 99r(ctjtj|}|dr|d}|S)z Clean the first part of a URL path that corresponds to a local filesystem path (i.e. the first part after splitting on "@" characters). z///z//)rgrequest pathname2url url2pathname startswith removeprefix)rerets r&_clean_file_url_pathrs|sU . % %fn&A&A$&G&G H HC ~~e%t$$ Jr(z(@|%2F)path is_local_pathrBcb|rt}nt}t|}g}t t j|dgD]J\}}|||||Kd |S)z* Clean the path portion of a URL. ) rsrk_reserved_chars_resplitr itertoolschainappendupperrQ)rtru clean_funcparts cleaned_partsto_cleanreserveds r&_clean_url_pathrs*) )   $ $T * *EM&yurd'C'CDD//(ZZ11222X^^--.... 77= ! !!r(r1c tj|}|j }t |j|}tj|d|}|j|ddz}|S)z Make sure a link is fully quoted. For example, if ' ' occurs in the URL, it will be replaced with "%20", and without double-quoting other characters. )rufile)schemertN) rgrhurlsplitnetlocrrt urlunsplit_replacer)r1resultrurtrrs r&_ensure_quoted_urlrsw\ " "3 ' 'F %M 6;m D D DD , ! !&//d/"K"K L LC -#abb' !C Jr(base_urlcp|dr|Stj||S)zk A faster implementation of urllib.parse.urljoin with a shortcut for absolute http/https URLs. )zhttps://zhttp://)rprgrhurljoin)rr1s r&_absolute_link_urlrs6  ~~-..3 |##Hc222r(ceZdZdZgdZ dDdEdZedFdZedGdZdHdZ dHdZ dId!Z dJd$Z dJd%Z edHd&ZedHd'ZedHd(ZedHd)ZedHd*ZedHd+ZedHd,ZdKd.ZedHd/ZedHd0Zejd1Zejd2ejZdLd3Zejd4ZedLd5Z dMd6Z!dNd8Z"edLd9Z#edLd:Z$edHd;Z%edOd<Z&dOd=Z'edOd>Z(edOd?Z)edOd@Z*edOdAZ+dPdCZ,dS)QLinkz:Represents a parsed link from a Package Index's simple URL) _parsed_url_url_path_hashes comes_fromrequires_python yanked_reasonmetadata_file_datacache_link_parsing egg_fragmentNTr1rrstr | IndexContent | Noner str | NonerrMetadataFile | NonerrBr@Mapping[str, str] | Noner*r+c|drt|}tj||_||_tj|jj|_ t |}|in| } || |_ n i|| |_ ||_|r|nd|_||_||_||_||_dS)a :param url: url of the resource pointed to (href of the link) :param comes_from: instance of IndexContent 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 metadata_file_data: the metadata attached to the file, or None if no such metadata is provided. This argument, if not None, indicates that a separate metadata file exists, and also optionally supplies hashes for that file. :param cache_link_parsing: A flag that is used elsewhere to determine whether resources retrieved from this link should be cached. PyPI URLs should generally have this set to False, for example. :param hashes: A mapping of hash names to digests to allow us to determine the validity of a download. z\\N)rprrgrhrrrrjrtrrr:r=rrrrrr _egg_fragmentr) r/r1rrrrrr@ link_hashhashes_from_links r&__init__z Link.__init__sP >>& ! ! #c""C!<0055 \))$*:*?@@ 33C88 !*!222 8I8I8K8K >+DLL9f9(89DL$2AKt*"4"4 ..00r( file_datadict[str, Any]page_url Link | Nonec0|d}|dStt||}|d}|d}|di}|d}||d}t|trt t |} n|rt d} nd} |rt|tsd}n|sd}||||||| S) zZ Convert an pypi json document from a simple repository page into a Link. r1Nzrequires-pythonyankedr@z core-metadatazdist-info-metadatarw)rrrr@r)getrr isinstancedictrWrdr) r8rrfile_urlr1 pyrequirerr@ metadata_infors r& from_jsonzLink.from_jsonsB==''  4 !3Hh!G!GHHMM"344 ! h// x,," o66  %MM*>??M mT * * &!-.>}.M.M!N!N    &!-d!3!3  "&   !M3!?!? !MM ! Ms %'1     r(anchor_attribsdict[str, str | None]rc@|d}|sdStt||}|d}|d}|d}||d}|dkrtd} nm|d} nh|d\} } } | dkrtt | | i} n*t d |td} |||||| S) z_ Convert an anchor element's attributes in a simple repository page to a Link. hrefNzdata-requires-pythonz data-yankedzdata-core-metadatazdata-dist-info-metadatatrue=z8Index returned invalid data-dist-info-metadata value: %s)rrrr)rrrrW partitionrdloggerdebug) r8rrrrr1rrrrhashnamesephashvals r& from_elementzLink.from_elementJsZ!!&)) 4 !3Hd!C!CDD"&&'=>> &**=99 '**+?@@  *../HIIM F " "!-d!3!3    "!%  &3%<%rUr.s r&__repr__z Link.__repr__sr(intc*t|jSr!)hashr1r.s r&__hash__z Link.__hash__sDH~~r(otherrcZt|tstS|j|jkSr!rrNotImplementedr1r/rs r&__eq__z Link.__eq__s)%&& "! !x59$$r(cZt|tstS|j|jkSr!rrs r&__lt__z Link.__lt__s)%&& "! !x%)##r(c|jSr!)rr.s r&r1zLink.urls yr(c*t|jSr!)r r1r.s r&rzLink.redacted_urls#DH---r(c|jd}tj|}|st |j\}}|St j|}|sJd|j d|S)N/zURL z produced no filename) rtrstrip posixpathbasenamerrrgrhrjr)r/rtrr user_passs r&filenamez Link.filenamesy$$!$'' !7t{ C C FIM|##D))>>>DI>>>>>t r(c*t|jSr!)rr1r.s r& file_pathzLink.file_paths48$$$r(c|jjSr!)rrr.s r&rz Link.schemes&&r(c|jjS)z4 This can contain auth information. )rrr.s r&rz Link.netlocs &&r(c|jSr!)rr.s r&rtz Link.paths zr(tuple[str, str]ctttj|jdS)Nr)rrrrtrr.s r&rz Link.splitexts+ *49+;+;C+@+@AABBBr(c6|dSN)rr.s r&extzLink.exts}}q!!r(cd|j\}}}}}tj||||dfS)Nrw)rrgrhr)r/rrrtqueryfragments r&url_without_fragmentzLink.url_without_fragments6040@-eX|&&eR'HIIIr(z[#&]egg=([^&]*)z)^([A-Z0-9]|[A-Z0-9][A-Z0-9._-]*[A-Z0-9])$c|j|j}|sdS|d}|j|st |dddd|S)Nrz2 contains an egg fragment with a non-PEP 508 name.z8to use the req @ url syntax, and remove the egg fragmentz26.0ie3)reason replacementgone_inissue)_egg_fragment_rer6rgroup_project_name_rer9r )r/r9 project_names r&rzLink._egg_fragments%,,TY77 4{{1~~ $**<88  RRRV     r(z[#&]subdirectory=([^&]*)cr|j|j}|sdS|dSr)_subdirectory_fragment_rer6rr)r/r9s r&subdirectory_fragmentzLink.subdirectory_fragments7.55di@@ 4{{1~~r(c|jdS|jd}|jjt|St||jjS)z>>  " ) 1 %% %L)@)GHHHHr(r cbtd|jDS)Nci|] \}}||g SrUrU)r$kr`s r&raz"Link.as_hashes..s ???$!Qq1#???r()r rrbr.s r&r?zLink.as_hashess-??$,*<*<*>*>???@@@r(cjtt|jdSr!)nextiterrvaluesr.s r&rz Link.hashs(D,,..//666r(cFtt|jdSr!)rrrr.s r&r%zLink.hash_namesD&&---r(ctj|jddddddS)N#rr?)rrrryr.s r&show_urlz Link.show_urls=!$)//#q"9"9!"<"B"B3"J"J1"MNNNr(c|jdkS)Nr)rr.s r&is_filez Link.is_files{f$$r(cX|jo#tj|jSr!)r osrtisdirrr.s r&is_existing_dirzLink.is_existing_dir s|= dn = ==r(c"|jtkSr!)rr r.s r&is_wheelz Link.is_wheelsx?**r(c*ddlm}|j|jvS)Nr)vcs)pip._internal.vcsrr all_schemes)r/rs r&is_vcsz Link.is_vcss#)))))){co--r(c|jduSr!)rr.s r& is_yankedzLink.is_yankeds!--r(c*t|jSr!)rBrr.s r&has_hashz Link.has_hashsDL!!!r(rAcpdStfd|jDS)zS Return True if the link has a hash and it is allowed by `hashes`. NFc3JK|]\}}||VdSr!)rE)r$rr`r@s r&r'z'Link.is_hash_allowed..&s7QQDAq6))!Q//QQQQQQr()anyrrbrFs `r&rEzLink.is_hash_allowed s@ >5QQQQDL>>>+++X+...X. ...X."""X"RRRRRRr(rc<eZdZUdZded<ded<ded<ded <d S) _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. zurllib.parse.SplitResultparsedzdict[str, list[str]]rr subdirectoryr;r@N)rJrKrLrMrNrUr(r&r r )sN2%$$$r(r linkc|j}|jddd}|jdkr|sd}tj|jdvrt d| dd }n#ttf$rd }YnwxYwfd tD}t||d d tj|j|| S)N@rr localhosteggzIgnoring egg= fragment in %sr"rrwc6i|]}|v||dS)rrU)r$rrs r&raz_clean_link..Zs( L L LAa8mma!Qmmmr()rrr)r!rr"r@)rrrsplitrrgrhparse_qsrrr IndexErrorKeyErrorr-r rr)r#r!rr"r@rs @r& _clean_linkr.Is  F ] ! !#q ) )" -F }v|$$V_55H  3T::: /2  ! M L L L): L L LF fBDDl##FL11!    s=B B"!B"link1link2cBt|t|kSr!)r.)r/r0s r&links_equivalentr2cs u  U!3!3 33r()r@rXr*rX)rerr*r)rtrrurBr*r)r1rr*r)rrr1rr*r)r#rr*r )r/rr0rr*rB)7 __future__rrSrzloggingr rr" urllib.parsergcollections.abcr dataclassesrtypingrrrpip._internal.utils.deprecationr pip._internal.utils.filetypesr pip._internal.utils.hashesr pip._internal.utils.miscr r rrpip._internal.utils.urlsrrpip._internal.index.collectorr getLoggerrJrr-rrWrdrkrsrOrrxrrrtotal_orderingrr r.rTr2rUr(r&rAsT""""""  ######!!!!!! 766666999999------ >=======;::::::  8 $ $ L $2H2H2H2H2H2H2H2Hj $JJJJJJJJ::::$ RZ 2=99"""",&3333 `R`R`R`R`R`R`R`RF :@4 444444r(