a  zeQ&@s ddlZddlZddlZddlZddlZddlZddlmZm Z m Z m Z m Z m Z mZddlmZddlmZddlmZmZmZddlmZddlmZmZerddlmZeeZ d Z!Gd d d eZ"Gd d d e Z#e"e#dddZ$ej%dde"e"e&dddZ'dS)N) TYPE_CHECKINGDictList NamedTupleOptionalTupleUnion)WHEEL_EXTENSION)Hashes)redact_auth_from_urlsplit_auth_from_netlocsplitext)KeyBasedCompareMixin) path_to_url url_to_path)HTMLPage)sha1sha224sha384sha256sha512md5cs"eZdZdZgdZd>eeeedfeeeeeddfdd Z ed d d Z ed d d Z e ed ddZ e ed ddZe ed ddZe ed ddZe ed ddZe ed ddZeeefd ddZe ed ddZe ed ddZed Ze eed d!d"Zed#Ze eed d$d%Zed&jd'ed(Z e eed d)d*Z!e eed d+d,Z"e ed d-d.Z#e ed d/d0Z$ed d1d2Z%e ed d3d4Z&e ed d5d6Z'e ed d7d8Z(e ed d9d:Z)ee*ed;dr,r)r,r,r-__repr__bsz Link.__repr__cCs|jSN)rr5r,r,r-reszLink.urlcCsR|jd}t|}|s,t|j\}}|Stj|}|sNJd|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_pathwszLink.file_pathcCs|jjSr7)rschemer5r,r,r-rC{sz Link.schemecCs|jjS)z4 This can contain auth information. )rr=r5r,r,r-r=sz Link.netloccCstj|jjSr7)r$r%r>rr9r5r,r,r-r9sz Link.pathcCstt|jdS)Nr8)r r;r<r9r:r5r,r,r-r sz Link.splitextcCs |dSN)r r5r,r,r-extszLink.extcCs&|j\}}}}}tj||||dfS)Nr/)rr$r% urlunsplit)r)rCr=r9queryfragmentr,r,r-url_without_fragmentszLink.url_without_fragmentz[#&]egg=([^&]*)cCs |j|j}|sdS|dSrD)_egg_fragment_researchrgroupr)matchr,r,r- egg_fragmentszLink.egg_fragmentz[#&]subdirectory=([^&]*)cCs |j|j}|sdS|dSrD)_subdirectory_fragment_rerLrrMrNr,r,r-subdirectory_fragmentszLink.subdirectory_fragmentz({choices})=([a-f0-9]+)|)choicescCs |j|j}|r|dSdS)N_hash_rerLrrMrNr,r,r-hashs z Link.hashcCs |j|j}|r|dSdSrDrVrNr,r,r- hash_names zLink.hash_namecCs$t|jddddddS)N#rEr?)r;r<rsplitr5r,r,r-show_urlsz Link.show_urlcCs |jdkS)Nfile)rCr5r,r,r-is_filesz Link.is_filecCs|jotj|jSr7)r_osr9isdirrBr5r,r,r-is_existing_dirszLink.is_existing_dircCs |jtkSr7)rFr r5r,r,r-is_wheelsz Link.is_wheelcCsddlm}|j|jvS)Nr)vcs)pip._internal.vcsrdrC all_schemes)r)rdr,r,r-is_vcss z Link.is_vcscCs |jduSr7)rr5r,r,r- is_yankedszLink.is_yankedcCs |jduSr7)rYr5r,r,r-has_hashsz Link.has_hash)hashesr cCs@|dus|jsdS|jdus J|jdus.J|j|j|jdS)zG Return True if the link has a hash and it is allowed. NF) hex_digest)rirYrXis_hash_allowed)r)rjr,r,r-rls zLink.is_hash_allowed)NNNT)-__name__ __module__ __qualname____doc__ __slots__r1rrboolr(r3r6propertyrrArBrCr=r9rr rFrJrecompilerKrPrQrRr0join_SUPPORTED_HASHESrWrXrYr]r_rbrcrgrhrir rl __classcell__r,r,r*r-rsx .    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. parsedrH subdirectoryrjN) rmrnrorpr$r% SplitResult__annotations__rr1rr,r,r,r-rys  ry)linkr c s|j}|jddd}|jdkr*|s*d}tj|jdvrLt d|zdd }Wnt t fyvd }Yn0fd d t D}t |j|d d d tj|j||dS)N@rEr^ localhosteggzIgnoring egg= fragment in %sr{rr/cs"i|]}|vr||dqS)rr,).0krIr,r- z_clean_link..)r=rHrI)rzrHr{rj)rr=rsplitrCr$r%parse_qsrIloggerdebug IndexErrorKeyErrorrwry_replacerH)r~rzr=r{rjr,rr- _clean_links$   r)maxsize)link1link2r cCst|t|kSr7)r)rrr,r,r-links_equivalentsr)( functoolsloggingr`r;rt 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 getLoggerrmrrwrryr lru_cacherrrr,r,r,r-s*$     I