7i)QddlZddlZddlZddlZddlZddlZddlZddlm Z ddl m Z m Z m Z mZmZmZmZmZmZddlmZddlmZddlmZddlmZmZmZmZddlm Z dd l!m"Z"m#Z#e rdd l$m%Z%ejLe'Z(d Z)e d GddZ*e d GddZ+dee e,e,fdee e,e,ffdZ-de,de,fdZ.de,de,fdZ/ej`dejbZ2de,de3de,fdZ4de,de,fdZ5Gdde Z6Gd d!eZ7d"e6de7fd#Z8ejrd$d%e6d&e6de3fd'Z:y)(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)frozenc"eZdZUdZeed<eed<ejdjdjde DZ dd Z e ejd d ededfd ZdeeeffdZdefdZdeedefdZy )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#FK|]}tj|ywN)reescape).0 hash_names b/mnt/ssd/data/python-lab/ChefSystem/venv/lib/python3.12/site-packages/pip/_internal/models/link.py zLinkHash.AsUiRYYy1Us!)choicesreturnNc,|jtvsJyr%)r!_SUPPORTED_HASHESselfs r* __post_init__zLinkHash.__post_init__Esyy----maxsizeurlcx|jj|}|y|j\}}|||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_fragmentHs>))005 =lln eE**r3c2|j|jiSr%r8r0s r*as_dictzLinkHash.as_dictRs 4::&&r3cFt|j|jgiS)z@Return a Hashes instance which checks only for the current hash.)rr!r"r0s r* as_hasheszLinkHash.as_hashesUstyy4::,/00r3hashescV|y|j|j|jS)zI Return True if the current hash is allowed by `hashes`. F) hex_digest)is_hash_allowedr!r"r1rCs r*rFzLinkHash.is_hash_allowedYs* >%%diiDJJ%GGr3r-N)__name__ __module__ __qualname____doc__str__annotations__r&compileformatjoinr/r9r2 classmethod functools lru_cacher r>rr@rrBboolrFr3r*r r ,s7 I J&BJJ #))HHUCTUU * .Y&++*1E+'+'c3h'161Hhv&6H4Hr3r c4eZdZUdZeeeefed<ddZy) MetadataFilezFInformation about a core metadata file associated with a distribution.rCNcZ|jtd|jDsJyy)Nc3,K|] }|tvywr%)r/)r(r!s r*r+z-MetadataFile.__post_init__..jsITt00Is)rCallr0s r*r2zMetadataFile.__post_init__hs) ;; "IT[[II II #r3rH) rIrJrKrLr rrMrNr2rVr3r*rXrXbsP T#s(^ $$Jr3rXrCr-cv|y|jDcic]\}}|tvs||}}}|sy|Scc}}wr%)itemsr/)rCnvs r*supported_hashesr`msF~%||~ Htq!6G1Gad HF H  MIs55partcztjjtjj|S)zP Clean a "part" of a URL path (i.e. after splitting on "@" characters). )urllibparsequoteunquoteras r*_clean_url_path_partrhxs( <<  fll2248 99r3cztjjtjj|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). )rcrequest pathname2url url2pathnamergs r*_clean_file_url_pathrms( >> & &v~~'B'B4'H IIr3z(@|%2F)path is_local_pathc,|rt}nt}tj|}g}t t j |dgD];\}}|j|||j|j=dj|S)z* Clean the path portion of a URL. ) rmrh_reserved_chars_resplitr itertoolschainappendupperrQ)rnro clean_funcparts cleaned_partsto_cleanreserveds r*_clean_url_pathr}s) )   $ $T *EM&yurd'CD/(Z12X^^-./ 77= !!r3r6ctjj|}|j }t |j |}tjj |j|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. )ro)rn)rcrdurlparsenetlocr}rn urlunparse_replace)r6resultrorns r*_ensure_quoted_urlrsT\\ " "3 'F %M 6;;m DD << " "6???#= >>r3c|eZdZdZgdZ d0dedeeedfdeedeed eed e d ee eefd dffd Z e de eefded edfdZe de eeefdeded edfdZd efdZd efdZed efdZed efdZed efdZed efdZed efdZed efdZd eeeffdZed efdZed efdZej>dZ ej>d ejBZ"d eefd!Z#ej>d"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 fd/Z2xZ3S)1Linkz: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_fragmentNr6rrrrrrrCr-c|jdr t|}tjj ||_||_tj|}|in|j} || |_ n i|| |_ ||_ |r|nd|_ ||_ ||_t |A|t"||_|j'|_y)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) startswithrrcrdurlsplitrrr r>r@rrrrrsuper__init__rr _egg_fragmentr) r1r6rrrrrrC link_hashhashes_from_link __class__s r*rz Link.__init__sP >>& !c"C!<<005 33C8 !*!22 8I8I8K >+DL9f9(89DL$2At*"4 S6"4 ..0r3 file_datapage_urlc|jd}|yttjj ||}|jd}|jd}|jdi}|jd}||jd}t |t rtt|} n|r td} 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-metadatarq)rrrrCr) getrrcrdurljoin isinstancedictrXr`rM) r<rrfile_urlr6 pyrequirerrC metadata_infors r* from_jsonzLink.from_jsons=='   !5!5h!IJMM"34 ! h/ x," o6  %MM*>?M mT *!-.>}.M!N  !-d!3 "&  M3!?M M %'1   r3anchor_attribsbase_urlc|jd}|syttjj ||}|jd}|jd}|jd}||jd}|dk(r t d} nW|d} nR|j d\} } } | dk(rt t| | i} n!tjd |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) rrrcrdrrX partitionr`loggerdebug) r<rrrrr6rrrrhashnamesephashvals r* from_elementzLink.from_element9s!!&) !5!5h!EF"&&'=> &**=9 '**+?@  *../HIM F "!-d!3   "!% &3%<%rVr0s r*__repr__z Link.__repr__wsvQr3c|jSr%)rr0s r*r6zLink.urlzs yyr3c |jjd}tj|}|st |j \}}|St jj|}|sJd|jd|S)N/zURL z produced no filename) rnrstrip posixpathbasenamerrrcrdrfr)r1rnr!r user_passs r*filenamez Link.filename~swyy$!!$'!7t{{ C FIM||##D)>tDII=(=>>t r3c,t|jSr%)rr6r0s r* file_pathzLink.file_paths488$$r3c.|jjSr%)rschemer0s r*rz Link.schemes&&&r3c.|jjS)z4 This can contain auth information. )rrr0s r*rz Link.netlocs &&&r3chtjj|jjSr%)rcrdrfrrnr0s r*rnz Link.paths#||##D$4$4$9$9::r3cpttj|jj dS)Nr)rrrrnrr0s r*rz Link.splitexts' **499+;+;C+@ABBr3c(|jdSN)rr0s r*extzLink.exts}}q!!r3cn|j\}}}}}tjj||||dfS)Nrq)rrcrd urlunsplit)r1rrrnqueryfragments r*url_without_fragmentzLink.url_without_fragments8040@0@-eX||&&eR'HIIr3z[#&]egg=([^&]*)z)^([A-Z0-9]|[A-Z0-9][A-Z0-9._-]*[A-Z0-9])$c|jj|j}|sy|jd}|jj |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 )r1r= project_names r*rzLink._egg_fragmentsi%%,,TYY7{{1~ $$**<8 PQV  r3z[#&]subdirectory=([^&]*)ct|jj|j}|sy|jdSr)_subdirectory_fragment_rer:rr)r1r=s r*subdirectory_fragmentzLink.subdirectory_fragments0..55dii@{{1~r3c|jy|jd}|jj t|St||jjS)z  " " ) ) 1 % %L)@)@)G)GHHr3c~t|jjDcic] \}}||g c}}Scc}}wr%)rrr])r1kr_s r*rBzLink.as_hashess2$,,*<*<*>?$!Qq1#v?@@?s9 c\tt|jjdSr%)nextiterrvaluesr0s r*hashz Link.hashs!D,,./66r3c@tt|jdSr%)rrrr0s r*r)zLink.hash_namesD&--r3ctj|jjdddjdddS)N#rr?)rrrrsr0s r*show_urlz Link.show_urls9!!$))//#q"9!"<"B"B3"J1"MNNr3c |jdk(S)Nfile)rr0s r*is_filez Link.is_files{{f$$r3cp|jxr)tjj|jSr%)rosrnisdirrr0s r*is_existing_dirzLink.is_existing_dirs"||= dnn ==r3c(|jtk(Sr%)rrr0s r*is_wheelz Link.is_wheelsxx?**r3c>ddlm}|j|jvS)Nr)vcs)pip._internal.vcsrr all_schemes)r1rs r*is_vcsz Link.is_vcss){{coo--r3c|jduSr%)rr0s r* is_yankedzLink.is_yankeds!!--r3c,t|jSr%)rUrr0s r*has_hashz Link.has_hashsDLL!!r3cbytfd|jjDS)zS Return True if the link has a hash and it is allowed by `hashes`. Fc3HK|]\}}j||ywr%)rF)r(rr_rCs r*r+z'Link.is_hash_allowed..s"QDAq6))!Q/Qs")anyrr]rGs `r*rFzLink.is_hash_alloweds+ >QDLL0 0  &  0 0 d1 S(3-/01 1  1 &  1 1 f88 # S #  %3%%'''''' ;c;;C%S/C"S""JcJJ"rzz"45"rzz4bmmx}$!+ +F G x} Ix/IA6A7hsm77.8C=..O#OO%%%>>+$++... .4.."$""Rhv&6R4Rr3rc|eZdZUdZej j ed<ee e e fed<e ed<ee e fed<y) _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) rIrJrKrLrcrd SplitResultrNrrMrrVr3r*rrs@2 LL $ $$ T#Y  cNr3rlinkc|j}|jjddd}|jdk(r|sd}tj j |j}d|vrtjd| |dd }tDcic]}||vs|||d }}t|j|d d tj j |j|| S#ttf$rd }YzwxYwcc}w) N@rr localhosteggzIgnoring egg= fragment in %sr rrq)rrr)r rr rC)rrrsplitrrcrdparse_qsrrr IndexErrorKeyErrorr/rrr)r r rrr rrCs r* _clean_linkr's   F ]] ! !#q )" -F }}v||$$V__5H  3T: /2 *; LAa8ma!Q LF L fBDll##FLL1!    ! MsC2 D  D 2DDr4link1link2c0t|t|k(Sr%)r)rrs r*links_equivalentrAs u U!3 33r3);rSrtloggingrrr& urllib.parserc 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 getLoggerrIrr/r rXrMr`rhrmrOrrrrUr}rrrrrTrrVr3r*r's  !   79- <=:   8 $ L $2H2H2Hj $JJJXd38n5(4S>:R:s:s: Js Js J RZZ 2==9"#"d"s", ?C ?C ?NR NRb :@d|4T"4D44$4#4r3