idSQddlZddlZddlZddlZddlZddlZddlZddlm Z ddl m Z m Z m Z mZmZmZmZmZmZddlmZddlmZddlmZddlmZmZmZmZddlm Z dd l!m"Z"m#Z#e rdd l$m%Z%ej&e'Z(d Z)e d GddZ*e d GddZ+dee e,e,fdee e,e,ffdZ-de,de,fdZ.de,de,fdZ/ej0dej1Z2de,de3de,fdZ4de,de,fdZ5Gdde Z6Gd d!eZ7d"e6de7fd#Z8ej9d$d%e6d&e6de3fd'Z:dS)(N) dataclass) TYPE_CHECKINGAnyDictListMapping NamedTupleOptionalTupleUnion) deprecated)WHEEL_EXTENSION)Hashes)pairwiseredact_auth_from_urlsplit_auth_from_netlocsplitext)KeyBasedCompareMixin) path_to_url url_to_path) IndexContent)sha512sha384sha256sha224sha1md5T)frozencPeZdZUdZeed<eed<ejdd de DZ dd Z e ejd d ededfd ZdeeeffdZdefdZdeedefdZd S)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()`.namevaluez[#&]({choices})=([^&]*)|c#>K|]}tj|VdSN)reescape).0 hash_names N/opt/cloudlinux/venv/lib/python3.11/site-packages/pip/_internal/models/link.py zLinkHash.As,UUiRYy11UUUUUU)choicesreturnNc&|jtvsJdSr%)r!_SUPPORTED_HASHESselfs r* __post_init__zLinkHash.__post_init__Esy-------r,maxsizeurlc|j|}|dS|\}}|||S)zGSearch a string for a checksum algorithm name and encoded output value.Nr!r")_hash_url_fragment_researchgroups)clsr6matchr!r"s r*find_hash_url_fragmentzLinkHash.find_hash_url_fragmentHsJ)0055 =4llnn esE****r,c|j|jiSr%r8r1s r*as_dictzLinkHash.as_dictRs 4:&&r,c:t|j|jgiS)z@Return a Hashes instance which checks only for the current hash.)rr!r"r1s r* as_hasheszLinkHash.as_hashesUsty4:,/000r,hashescL|dS||j|jS)zI Return True if the current hash is allowed by `hashes`. NF) hex_digest)is_hash_allowedr!r"r2rCs r*rFzLinkHash.is_hash_allowedYs+ >5%%diDJ%GGGr,r.N)__name__ __module__ __qualname____doc__str__annotations__r&compileformatjoinr0r9r3 classmethod functools lru_cacher r>rr@rrBboolrFr,r*r r ,sP77 III JJJ&BJ #))HHUUCTUUUUU *   ....Y&&&++*1E+++'&[+'c3h''''161111Hhv&6H4HHHHHHr,r cBeZdZUdZeeeefed<ddZdS) MetadataFilezFInformation about a core metadata file associated with a distribution.rCr.NcX|j td|jDsJdSdS)Nc3(K|] }|tvVdSr%r0)r(r!s r*r+z-MetadataFile.__post_init__..js(IITt00IIIIIIr,)rCallr1s r*r3zMetadataFile.__post_init__hs= ; "IIT[IIIII I I I # " I Ir,rH) rIrJrKrLr rrMrNr3rVr,r*rXrXbsOPP T#s(^ $$$$JJJJJJr,rXrCr.cR|dSd|D}|sdS|S)Nc,i|]\}}|tv||SrVr[)r(nvs r* z$supported_hashes..rs) H H Htq!6G1G1Ga1G1G1Gr,)itemsrCs r*supported_hashesrdms;~t H Hv||~~ H H HF t Mr,partcztjtj|S)zP Clean a "part" of a URL path (i.e. after splitting on "@" characters). )urllibparsequoteunquoteres r*_clean_url_path_partrlxs* <  fl22488 9 99r,cztjtj|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). )rgrequest pathname2url url2pathnamerks r*_clean_file_url_pathrqs* > & &v~'B'B4'H'H I IIr,z(@|%2F)path is_local_pathcb|rt}nt}t|}g}t t j|dgD]J\}}|||||Kd |S)z* Clean the path portion of a URL. ) rqrl_reserved_chars_resplitr itertoolschainappendupperrQ)rrrs clean_funcparts cleaned_partsto_cleanreserveds r*_clean_url_pathrs*) )   $ $T * *EM&yurd'C'CDD//(ZZ11222X^^--.... 77= ! !!r,r6ctj|}|j }t |j|}tj||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. )rs)rr)rgrhurlparsenetlocrrr urlunparse_replace)r6resultrsrrs r*_ensure_quoted_urlrs[\ " "3 ' 'F %M 6;m D D DD < " "6???#=#= > >>r,cJeZdZdZgdZ d1dedeeedfdeed eed eed e d ee eefd dffd Z e de eefded edfdZe de eeefdeded edfdZd efdZd efdZed efdZed efdZed efdZed efdZed efdZed efdZd eeeffdZed efdZed efdZejd Z ejd!ej!Z"d eefd"Z#ejd#Z$ed eefd$Z%d edfd%Z&d e'fd&Z(ed eefd'Z)ed eefd(Z*ed efd)Z+ed e fd*Z,d e fd+Z-ed e fd,Z.ed e fd-Z/ed e fd.Z0ed e fd/Z1d ee'd e fd0Z2xZ3S)2Linkz:Represents a parsed link from a Package Index's simple URL) _parsed_url_url_hashes comes_fromrequires_python yanked_reasonmetadata_file_datacache_link_parsing egg_fragmentNTr6rrrrrrrCr.c|drt|}tj||_||_t|}|in| } || |_ n i|| |_ ||_ |r|nd|_ ||_ ||_t|t"||_||_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)keydefining_class) startswithrrgrhurlsplitrrr r>r@rrrrrsuper__init__rr _egg_fragmentr) r2r6rrrrrrC link_hashhashes_from_link __class__s r*rz Link.__init__sP >>& ! ! #c""C!<0055 33C88 !*!222 8I8I8K8K >+DLL9f9(89DL$2AKt*"4 S666"4 ..00r, file_datapage_urlcP|d}|dSttj||}|d}|d}|di}|d}||d}t |t rtt|} n|rtd} nd} |rt |tsd}n|sd}||||||| S) zZ Convert an pypi json document from a simple repository page into a Link. r6Nzrequires-pythonyankedrCz core-metadatazdist-info-metadataru)rrrrCr) getrrgrhurljoin isinstancedictrXrdrM) r<rrfile_urlr6 pyrequirerrC metadata_infors r* from_jsonzLink.from_jsonsI==''  4 !5!5h!I!IJJMM"344 ! h// x,," o66  %MM*>??M mT * * &!-.>}.M.M!N!N    &!-d!3!3  "&   !M3!?!? !MM ! Ms %'1     r,anchor_attribsbase_urlc`|d}|sdSttj||}|d}|d}|d}||d}|dkrt d} nm|d} nh|d\} } } | dkrt t| | i} n*t d |t d} |||||| 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) rrrgrhrrX partitionrdloggerdebug) r<rrrrr6rrrrhashnamesephashvals r* from_elementzLink.from_element9sa!!&)) 4 !5!5h!E!EFF"&&'=>> &**=99 '**+?@@  *../HIIM F " "!-d!3!3    "!%  &3%<%rVr1s r*__repr__z Link.__repr__ysr,c|jSr%)rr1s r*r6zLink.url|s yr,c|jd}tj|}|st |j\}}|St j|}|sJd|j d|S)N/zURL z produced no filename) rrrstrip posixpathbasenamerrrgrhrjr)r2rrr!r user_passs r*filenamez Link.filenamesy$$!$'' !7t{ C C FIM|##D))>>>DI>>>>>> r,c*t|jSr%)rr6r1s r* file_pathzLink.file_paths48$$$r,c|jjSr%)rschemer1s r*rz Link.schemes&&r,c|jjS)z4 This can contain auth information. )rrr1s r*rz Link.netlocs &&r,cTtj|jjSr%)rgrhrjrrrr1s r*rrz Link.paths|##D$4$9:::r,ctttj|jdS)Nr)rrrrrrr1s r*rz Link.splitexts+ *49+;+;C+@+@AABBBr,c6|dSN)rr1s r*extzLink.exts}}q!!r,cd|j\}}}}}tj||||dfS)Nru)rrgrh urlunsplit)r2rrrrqueryfragments 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)Nrz1 contains an egg fragment with a non-PEP 508 namez8to use the req @ url syntax, and remove the egg fragmentz25.0ia-)reason replacementgone_inissue)_egg_fragment_rer:rgroup_project_name_rer=r )r2r= project_names r*rzLink._egg_fragments%,,TY77 4{{1~~ $**<88  QQQV     r,z[#&]subdirectory=([^&]*)cr|j|j}|sdS|dSr)_subdirectory_fragment_rer:rr)r2r=s r*subdirectory_fragmentzLink.subdirectory_fragments7.55di@@ 4{{1~~r,c|jdS|jd}|jjt|St||jjS)z>>  " ) 1 %% %L)@)GHHHHr,cbtd|jDS)Nci|] \}}||g SrVrV)r(kr`s r*raz"Link.as_hashes..s ???$!Qq1#???r,)rrrbr1s r*rBzLink.as_hashess-??$,*<*<*>*>???@@@r,cjtt|jdSr%)nextiterrvaluesr1s r*hashz Link.hashs(D,,..//666r,cFtt|jdSr%)rrrr1s r*r)zLink.hash_namesD&&---r,ctj|jddddddS)N#rr?)rrrrwr1s r*show_urlz Link.show_urls=!$)//#q"9"9!"<"B"B3"J"J1"MNNNr,c|jdkS)Nfile)rr1s r*is_filez Link.is_files{f$$r,cX|jo#tj|jSr%)rosrrisdirrr1s r*is_existing_dirzLink.is_existing_dirs|= dn = ==r,c"|jtkSr%)rrr1s r*is_wheelz Link.is_wheelsx?**r,c*ddlm}|j|jvS)Nr)vcs)pip._internal.vcsrr all_schemes)r2rs r*is_vcsz Link.is_vcss#)))))){co--r,c|jduSr%)rr1s r* is_yankedzLink.is_yankeds!--r,c*t|jSr%)rUrr1s r*has_hashz Link.has_hashsDL!!!r,cpdStfd|jDS)zS Return True if the link has a hash and it is allowed by `hashes`. NFc3JK|]\}}||VdSr%)rF)r(rr`rCs r*r+z'Link.is_hash_allowed..s7QQDAq6))!Q//QQQQQQr,)anyrrbrGs `r*rFzLink.is_hash_alloweds@ >5QQQQDL0 0  &  0 0 0 [0 d1 S(3-/01 1  1 &  1 1 1 [1 f 8 8 8 8 8 #    SX #   X %3%%%X%''''X'''''X' ;c;;;X;C%S/CCCC"S"""X"JcJJJXJ"rz"455"rz4bmx}$!+ +F G G x}X Ix/IIIIA6AAAA7hsm777X7.8C=...X.O#OOOXO%%%%X%>>>>>+$+++X+....X. .4...X."$"""X"Rhv&6R4RRRRRRRRr,rc|eZdZUdZejjed<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. parsedr subdirectoryrCN) rIrJrKrLrgrh SplitResultrNrrMrrVr,r*r r  sh2 L $$$$ T#Y  cNr,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 %srrruc6i|]}|v||dS)rrV)r(rrs r*raz_clean_link..:s( L L LAa8mma!Qmmmr,)rrr)rrrrC)rrrsplitrrgrhparse_qsrrr IndexErrorKeyErrorr0r rr)rrrrrCrs @r* _clean_linkr)s  F ] ! !#q ) )" -F }v|$$V_55H  3T::: /2  ! M L L L): L L LF fBDDl##FL11!    s=B B"!B"r4link1link2cBt|t|kSr%)r)rrs r*links_equivalentr Cs u  U!3!3 33r,);rSrxloggingrrr& urllib.parserg dataclassesrtypingrrrrrr r r r pip._internal.utils.deprecationr pip._internal.utils.filetypesrpip._internal.utils.hashesrpip._internal.utils.miscrrrrpip._internal.utils.modelsrpip._internal.utils.urlsrrpip._internal.index.collectorr getLoggerrIrr0r rXrMrdrlrqrOr rvrUrrrr rrTr rVr,r*r-s  !!!!!!                      766666999999------ <;;;;;========;::::::  8 $ $ L $2H2H2H2H2H2H2H2Hj $JJJJJJJJXd38n5(4S>:R:s:s:::: Js Js J J J J RZ 2=99"#"d"s"""", ?C ?C ? ? ? ?PRPRPRPRPR PRPRPRf :@d|4T"""4D44$444#"444r,