U ja'@sddlZddlZddlZddlZddlZddlZddlmZm Z m Z m Z m Z m Z mZddlmZddlmZddlmZmZmZddlmZddlmZmZerddlmZeeZ d Z!Gd d d eZ"Gd d d e Z#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*eZdZdZddddddgZdCeeeed feeeeedd fd d Z edddZ edddZ e edddZ e edddZe edddZe edddZe edddZe edddZeeefddd Ze edd!d"Ze edd#d$Zed%Ze eedd&d'Zed(Ze eedd)d*Zed+jd,ed-Z e eedd.d/Z!e eedd0d1Z"e edd2d3Z#e edd4d5Z$edd6d7Z%e edd8d9Z&e edd:d;Z'e eddd?Z)ee*ed@dAdBZ+Z,S)DLinkz?Represents a parsed link from a Package Index's simple URL _parsed_url_url comes_fromrequires_python yanked_reasoncache_link_parsingNTr)urlrrrrreturncsZ|drt|}tj||_||_||_|r4|nd|_||_ t j |t d||_ dS)a :param url: url of the resource pointed to (href of the link) :param comes_from: instance of HTMLPage 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 cache_link_parsing: A flag that is used elsewhere to determine whether resources retrieved from this link should be cached. PyPI index urls should generally have this set to False, for example. z\\N)keydefining_class) startswithrurllibparseurlsplitrrrrrsuper__init__rr)selfrrrrr __class__q/private/var/folders/k6/_7fsz4ts3b78x3b3xwrxjh_c8s8xv7/T/pip-unpacked-wheel-bug3gbve/pip/_internal/models/link.pyr()s z Link.__init__)r cCsH|jrd|jd}nd}|jr6dt|j|j|Stt|jSdS)Nz (requires-python:)z{} (from {}){})rrformatr rstr)r)rpr,r,r-__str__Wsz Link.__str__cCs d|dS)Nzr,r)r,r,r-__repr__bsz Link.__repr__cCs|jSN)rr5r,r,r-reszLink.urlcCsR|jd}t|}|s,t|j\}}|Stj|}|sNt d|j d|S)N/zURL z produced no filename) pathrstrip posixpathbasenamer netlocr$r%unquoteAssertionErrorr)r)r9namer= user_passr,r,r-filenameis   z Link.filenamecCs t|jSr7)rrr5r,r,r- file_pathwszLink.file_pathcCs|jjSr7)rschemer5r,r,r-rD{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)rDr=r9queryfragmentr,r,r-url_without_fragmentszLink.url_without_fragmentz[#&]egg=([^&]*)cCs |j|j}|sdS|dSrE)_egg_fragment_researchrgroupr)matchr,r,r- egg_fragmentszLink.egg_fragmentz[#&]subdirectory=([^&]*)cCs |j|j}|sdS|dSrE)_subdirectory_fragment_rerMrrNrOr,r,r-subdirectory_fragmentszLink.subdirectory_fragmentz({choices})=([a-f0-9]+)|)choicescCs |j|j}|r|dSdS)N_hash_rerMrrNrOr,r,r-hashs z Link.hashcCs |j|j}|r|dSdSrErWrOr,r,r- hash_names zLink.hash_namecCs$t|jddddddS)N#rFr?)r;r<rsplitr5r,r,r-show_urlsz Link.show_urlcCs |jdkS)Nfile)rDr5r,r,r-is_filesz Link.is_filecCs|jotj|jSr7)r`osr9isdirrCr5r,r,r-is_existing_dirszLink.is_existing_dircCs |jtkSr7)rGr r5r,r,r-is_wheelsz Link.is_wheelcCsddlm}|j|jkS)Nr)vcs)pip._internal.vcsrerD all_schemes)r)rer,r,r-is_vcss z Link.is_vcscCs |jdk Sr7)rr5r,r,r- is_yankedszLink.is_yankedcCs |jdk Sr7)rZr5r,r,r-has_hashsz Link.has_hash)hashesr cCs@|dks|jsdS|jdk s t|jdk s.t|j|j|jdS)zG Return True if the link has a hash and it is allowed. NF) hex_digest)rjrZr?rYis_hash_allowed)r)rkr,r,r-rms zLink.is_hash_allowed)NNNT)-__name__ __module__ __qualname____doc__ __slots__r1rrboolr(r3r6propertyrrBrCrDr=r9rr rGrKrecompilerLrQrRrSr0join_SUPPORTED_HASHESrXrYrZr^r`rcrdrhrirjr rm __classcell__r,r,r*r-rs .    rc@s^eZdZUdZejjed<ee e e fed<e ed<ee e fed<e e ddddZ d S) _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. parsedrI subdirectoryrk)linkr c s|j}|jddd}|jdkr*|s*d}tj|jdkrLt d|zdd }Wnt t fk rxd }YnXfd d t D}||j |d d d tj|j||dS)N@rFr_ localhostZeggzIgnoring egg= fragment in %sr|rr/cs"i|]}|kr||dqS)rr,).0krJr,r- sz*_CleanResult.from_link..)r=rIrJ)r{rIr|rk)rr=rsplitrDr$r%parse_qsrJloggerdebug IndexErrorKeyErrorrx_replacerI)clsr}r{r=r|rkr,rr- from_links$   z_CleanResult.from_linkN)rnrorprqr$r% SplitResult__annotations__rr1r classmethodrrr,r,r,r-rzs  rz)maxsize)link1link2r cCst|t|kSr7)rzr)rrr,r,r-links_equivalentsr)' functoolsloggingrar;ru 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 getLoggerrnrrxrrz lru_cachersrr,r,r,r-s($     I: