U ÀÒ.eÌ ã @ s´ d dl Z d dlZd dlZd dlmZ d dlmZ d dlm Z m Z mZ d dlm Z d dlmZ d dlmZmZ er d dlmZmZmZmZ d d lmZ d d lmZ G dd„ de ƒZdS ) é N)Úparse)ÚWHEEL_EXTENSION)Úredact_auth_from_urlÚsplit_auth_from_netlocÚsplitext)ÚKeyBasedCompareMixin)ÚMYPY_CHECK_RUNNING)Úpath_to_urlÚurl_to_path)ÚOptionalÚTextÚTupleÚUnion)ÚHTMLPage)ÚHashesc s@ e Zd ZdZd6‡ fdd„ Zdd„ Zdd„ Zed d „ ƒZedd„ ƒZ ed d„ ƒZ edd„ ƒZedd„ ƒZedd„ ƒZ dd„ Zedd„ ƒZedd„ ƒZe d¡Zedd„ ƒZe d¡Zedd „ ƒZe d!¡Zed"d#„ ƒZed$d%„ ƒZed&d'„ ƒZed(d)„ ƒZd*d+„ Zed,d-„ ƒZed.d/„ ƒZed0d1„ ƒZed2d3„ ƒZ d4d5„ Z!‡ Z"S )7ÚLinkz?Represents a parsed link from a Package Index's simple URL Nc sV | d¡rt|ƒ}t |¡| _|| _|| _|r2|nd| _|| _t 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. z\\N)ÚkeyZdefining_class)Ú startswithr Úurllib_parseZurlsplitÚ_parsed_urlÚ_urlÚ comes_fromÚrequires_pythonÚ yanked_reasonÚsuperr Ú__init__)ÚselfÚurlr r r ©Ú __class__© ú=/usr/lib/python3.8/site-packages/pip/_internal/models/link.pyr s z Link.__init__c C sD | j rd| j }nd}| jr2dt| jƒ| j|f S tt| jƒƒS d S )Nz (requires-python:%s)Ú z%s (from %s)%s)r r r r Ústr)r Zrpr r r! Ú__str__E s ÿzLink.__str__c C s d| S )Nz r ©r r r r! Ú__repr__P s z Link.__repr__c C s | j S ©N)r r% r r r! r S s zLink.urlc C s: | j d¡}t |¡}|s,t| jƒ\}}|S t |¡}|S ©Nú/)ÚpathÚrstripÚ posixpathÚbasenamer Únetlocr Úunquote)r r* Únamer. Z user_passr r r! ÚfilenameX s z Link.filenamec C s t | jƒS r' )r r r% r r r! Ú file_pathg s zLink.file_pathc C s | j jS r' )r Úschemer% r r r! r3 l s zLink.schemec C s | j jS )z4 This can contain auth information. )r r. r% r r r! r. q s zLink.netlocc C s t | jj¡S r' )r r/ r r* r% r r r! r* y s z Link.pathc C s t t | j d¡¡ƒS r( )r r, r- r* r+ r% r r r! r ~ s z Link.splitextc C s | ¡ d S ©Né )r r% r r r! Úext‚ s zLink.extc C s$ | j \}}}}}t ||||d f¡S r' )r r Z urlunsplit)r r3 r. r* ZqueryZfragmentr r r! Úurl_without_fragment‡ s zLink.url_without_fragmentz[#&]egg=([^&]*)c C s | j | j¡}|sd S | d¡S r4 )Ú_egg_fragment_reÚsearchr Úgroup©r Úmatchr r r! Úegg_fragment� s zLink.egg_fragmentz[#&]subdirectory=([^&]*)c C s | j | j¡}|sd S | d¡S r4 )Ú_subdirectory_fragment_rer9 r r: r; r r r! Úsubdirectory_fragment™ s zLink.subdirectory_fragmentz2(sha1|sha224|sha384|sha256|sha512|md5)=([a-f0-9]+)c C s | j | j¡}|r| d¡S d S )Né ©Ú_hash_rer9 r r: r; r r r! Úhash¥ s z Link.hashc C s | j | j¡}|r| d¡S d S r4 rA r; r r r! Ú hash_name s zLink.hash_namec C s$ t | j dd¡d dd¡d ¡S )Nú#r5 r ú?)r, r- r Úsplitr% r r r! Úshow_urlµ s z Link.show_urlc C s | j dkS )NÚfile)r3 r% r r r! Úis_fileº s zLink.is_filec C s | j otj | j¡S r' )rJ Úosr* Úisdirr2 r% r r r! Úis_existing_dir¿ s zLink.is_existing_dirc C s | j tkS r' )r6 r r% r r r! Úis_wheelà s z Link.is_wheelc C s ddl m} | j|jkS )Nr )Úvcs)Zpip._internal.vcsrO r3 Zall_schemes)r rO r r r! Úis_vcsÈ s zLink.is_vcsc C s | j d k S r' )r r% r r r! Ú is_yankedÏ s zLink.is_yankedc C s | j d k S r' )rD r% r r r! Úhas_hashÔ s z Link.has_hashc C s$ |dks| j sdS |j| j| jd�S )zG Return True if the link has a hash and it is allowed. NF)Z hex_digest)rR Úis_hash_allowedrD rC )r Zhashesr r r! rS Ø s zLink.is_hash_allowed)NNN)#Ú__name__Ú __module__Ú__qualname__Ú__doc__r r$ r&