a [fY&@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)Zsha1Zsha224Zsha384Zsha256Zsha512Zmd5cs"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)rr-r%r%r&reszLink.urlcCs<|jd}t|}|s,t|j\}}|Stj|}|SN/) pathrstrip posixpathbasenamer netlocrrunquote)r"r2namer6Z user_passr%r%r&filenameis   z Link.filenamecCs t|jSr/)rrr-r%r%r& file_pathwszLink.file_pathcCs|jjSr/)rschemer-r%r%r&r;{sz Link.schemecCs|jjS)z4 This can contain auth information. )rr6r-r%r%r&r6sz Link.netloccCstj|jjSr/)rrr7rr2r-r%r%r&r2sz Link.pathcCstt|jdSr0)r r4r5r2r3r-r%r%r&r sz Link.splitextcCs |dSN)r r-r%r%r&extszLink.extcCs&|j\}}}}}tj||||dfS)Nr()rrr urlunsplit)r"r;r6r2queryfragmentr%r%r&url_without_fragmentszLink.url_without_fragmentz[#&]egg=([^&]*)cCs |j|j}|sdS|dSr<)_egg_fragment_researchrgroupr"matchr%r%r& egg_fragmentszLink.egg_fragmentz[#&]subdirectory=([^&]*)cCs |j|j}|sdS|dSr<)_subdirectory_fragment_rerDrrErFr%r%r&subdirectory_fragmentszLink.subdirectory_fragmentz({choices})=([a-f0-9]+)|)choicescCs |j|j}|r|dSdS)N_hash_rerDrrErFr%r%r&hashs z Link.hashcCs |j|j}|r|dSdSr<rNrFr%r%r& hash_names zLink.hash_namecCs$t|jddddddS)N#r=r?)r4r5rsplitr-r%r%r&show_urlsz Link.show_urlcCs |jdkS)Nfile)r;r-r%r%r&is_filesz Link.is_filecCs|jotj|jSr/)rWosr2isdirr:r-r%r%r&is_existing_dirszLink.is_existing_dircCs |jtkSr/)r>r r-r%r%r&is_wheelsz Link.is_wheelcCsddlm}|j|jvS)Nr)vcs)Zpip._internal.vcsr\r;Z all_schemes)r"r\r%r%r&is_vcss z Link.is_vcscCs |jduSr/)rr-r%r%r& is_yankedszLink.is_yankedcCs |jduSr/)rQr-r%r%r&has_hashsz Link.has_hash)hashesrcCs$|dus|jsdS|j|j|jdS)zG Return True if the link has a hash and it is allowed. NF)Z hex_digest)r_is_hash_allowedrQrP)r"r`r%r%r&raszLink.is_hash_allowed)NNNT)-__name__ __module__ __qualname____doc__ __slots__r*rrboolr!r+r.propertyrr9r:r;r6r2rr r>rBrecompilerCrHrIrJr)join_SUPPORTED_HASHESrOrPrQrUrWrZr[r]r^r_r ra __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. parsedr@ subdirectoryr`N) rbrcrdrerr SplitResult__annotations__rr*rr%r%r%r&rns  rn)linkrc 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@r=rVZ localhostZeggzIgnoring egg= fragment in %srprr(cs"i|]}|vr||dqS)rr%).0krAr%r& z_clean_link..)r6r@rA)ror@rpr`)rr6rsplitr;rrparse_qsrAloggerdebug IndexErrorKeyErrorrlrn_replacer@)rsror6rpr`r%rxr& _clean_links$   r)maxsize)link1link2rcCst|t|kSr/)r)rrr%r%r&links_equivalentsr)( functoolsZloggingrXr4ri 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 getLoggerrbr}rlrrnr lru_cachergrr%r%r%r&s*$     I