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.urlcCsR|jd}t|}|s,t|j\}}|Stj|}|sNJd|j d|S)N/zURL z produced no filename) pathrstrip posixpathbasenamer netlocrrunquoter)r"r1namer5Z 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. )rr5r-r%r%r&r5sz Link.netloccCstj|jjSr/)rrr6rr1r-r%r%r&r1sz Link.pathcCstt|jdS)Nr0)r r3r4r1r2r-r%r%r&r sz Link.splitextcCs |dSN)r r-r%r%r&extszLink.extcCs&|j\}}}}}tj||||dfS)Nr()rrr urlunsplit)r"r:r5r1queryfragmentr%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_rerCrrDrEr%r%r&subdirectory_fragmentszLink.subdirectory_fragmentz({choices})=([a-f0-9]+)|)choicescCs |j|j}|r|dSdS)N_hash_rerCrrDrEr%r%r&hashs z Link.hashcCs |j|j}|r|dSdSr;rMrEr%r%r& hash_names zLink.hash_namecCs$t|jddddddS)N#r<r?)r3r4rsplitr-r%r%r&show_urlsz Link.show_urlcCs |jdkS)Nfile)r:r-r%r%r&is_filesz Link.is_filecCs|jotj|jSr/)rVosr1isdirr9r-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/)rPr-r%r%r&has_hashsz Link.has_hash)hashesrcCs@|dus|jsdS|jdus J|jdus.J|j|j|jdS)zG Return True if the link has a hash and it is allowed. NF)Z hex_digest)r^rPrOis_hash_allowed)r"r_r%r%r&r`s zLink.is_hash_allowed)NNNT)-__name__ __module__ __qualname____doc__ __slots__r*rrboolr!r+r.propertyrr8r9r:r5r1rr r=rArecompilerBrGrHrIr)join_SUPPORTED_HASHESrNrOrPrTrVrYrZr\r]r^r r` __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) rarbrcrdrr SplitResult__annotations__rr*rr%r%r%r&rms  rm)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<rUZ localhostZeggzIgnoring egg= fragment in %srorr(cs"i|]}|vr||dqS)rr%).0kr@r%r& z_clean_link..)r5r?r@)rnr?ror_)rr5rsplitr:rrparse_qsr@loggerdebug IndexErrorKeyErrorrkrm_replacer?)rrrnr5ror_r%rwr& _clean_links$   r)maxsize)link1link2rcCst|t|kSr/)r)rrr%r%r&links_equivalentsr)( functoolsZloggingrWr3rh 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 getLoggerrar|rkrrmr lru_cacherfrr%r%r%r&s*$     I