3
ÀÞL]™  ã               @   s˜   d dl Z d dlZd dlmZ d dlmZmZmZm	Z	m
Z
 d dlmZ d dlmZ er„d dlmZmZmZmZ d dlmZ d dlmZ G d	d
„ d
eƒZdS )é    N)Úparse)ÚWHEEL_EXTENSIONÚpath_to_urlÚredact_password_from_urlÚsplit_auth_from_netlocÚsplitext)ÚKeyBasedCompareMixin)ÚMYPY_CHECK_RUNNING)ÚOptionalÚTextÚTupleÚUnion)ÚHTMLPage)ÚHashesc                   s   e Zd ZdZd0‡ fdd„	Zdd„ Zdd„ Zed	d
„ ƒZedd„ ƒZ	edd„ ƒZ
edd„ ƒZedd„ ƒZdd„ Zedd„ ƒZedd„ ƒZejdƒZedd„ ƒZejdƒZedd„ ƒZejdƒZed d!„ ƒZed"d#„ ƒZed$d%„ ƒZed&d'„ ƒZed(d)„ ƒZed*d+„ ƒZed,d-„ ƒZd.d/„ Z‡  ZS )1ÚLinkz?Represents a parsed link from a Package Index's simple URL
    Nc                sV   |j dƒrt|ƒ}tj|ƒ| _|| _|| _|r2|nd| _|| _t	t
| ƒj|t
d� dS )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)ÚkeyÚdefining_class)Ú
startswithr   Úurllib_parseÚurlsplitÚ_parsed_urlÚ_urlÚ
comes_fromÚrequires_pythonÚyanked_reasonÚsuperr   Ú__init__)ÚselfÚurlr   r   r   )Ú	__class__© ú8/tmp/pip-build-69lrc5qx/pip/pip/_internal/models/link.pyr      s    
zLink.__init__c             C   sD   | j rd| j  }nd}| jr2dt| jƒ| j|f S tt| jƒƒS d S )Nz (requires-python:%s)Ú z%s (from %s)%s)r   r   r   r   Ústr)r   Úrpr    r    r!   Ú__str__>   s    
zLink.__str__c             C   s   d|  S )Nz	<Link %s>r    )r   r    r    r!   Ú__repr__I   s    zLink.__repr__c             C   s   | j S )N)r   )r   r    r    r!   r   L   s    zLink.urlc             C   sL   | j jdƒ}tj|ƒ}|s,t| jƒ\}}|S tj|ƒ}|sHtd| j	 ƒ‚|S )Nú/zURL %r produced no filename)
ÚpathÚrstripÚ	posixpathÚbasenamer   Únetlocr   ÚunquoteÚAssertionErrorr   )r   r(   Únamer,   Ú	user_passr    r    r!   ÚfilenameQ   s    

zLink.filenamec             C   s   | j jS )N)r   Úscheme)r   r    r    r!   r2   `   s    zLink.schemec             C   s   | j jS )z4
        This can contain auth information.
        )r   r,   )r   r    r    r!   r,   e   s    zLink.netlocc             C   s   t j| jjƒS )N)r   r-   r   r(   )r   r    r    r!   r(   m   s    z	Link.pathc             C   s   t tj| jjdƒƒƒS )Nr'   )r   r*   r+   r(   r)   )r   r    r    r!   r   r   s    zLink.splitextc             C   s   | j ƒ d S )Né   )r   )r   r    r    r!   Úextv   s    zLink.extc             C   s$   | j \}}}}}tj||||d fƒS )N)r   r   Ú
urlunsplit)r   r2   r,   r(   ÚqueryÚfragmentr    r    r!   Úurl_without_fragment{   s    zLink.url_without_fragmentz[#&]egg=([^&]*)c             C   s    | j j| jƒ}|sd S |jdƒS )Nr3   )Ú_egg_fragment_reÚsearchr   Úgroup)r   Úmatchr    r    r!   Úegg_fragmentƒ   s    zLink.egg_fragmentz[#&]subdirectory=([^&]*)c             C   s    | j j| jƒ}|sd S |jdƒS )Nr3   )Ú_subdirectory_fragment_rer:   r   r;   )r   r<   r    r    r!   Úsubdirectory_fragment�   s    zLink.subdirectory_fragmentz2(sha1|sha224|sha384|sha256|sha512|md5)=([a-f0-9]+)c             C   s    | j j| jƒ}|r|jdƒS d S )Né   )Ú_hash_rer:   r   r;   )r   r<   r    r    r!   Úhash™   s    
z	Link.hashc             C   s    | j j| jƒ}|r|jdƒS d S )Nr3   )rA   r:   r   r;   )r   r<   r    r    r!   Ú	hash_name¡   s    
zLink.hash_namec             C   s$   t j| jjddƒd jddƒd ƒS )Nú#r3   r   ú?)r*   r+   r   Úsplit)r   r    r    r!   Úshow_url©   s    zLink.show_urlc             C   s
   | j tkS )N)r4   r   )r   r    r    r!   Úis_wheel®   s    zLink.is_wheelc             C   s    ddl m} | j|jkrdS dS )z 
        Determines if this points to an actual artifact (e.g. a tarball) or if
        it points to an "abstract" thing like a path or a VCS location.
        r   )ÚvcsFT)Zpip._internal.vcsrI   r2   Úall_schemes)r   rI   r    r    r!   Úis_artifact³   s    zLink.is_artifactc             C   s
   | j d k	S )N)r   )r   r    r    r!   Ú	is_yankedÁ   s    zLink.is_yankedc             C   s
   | j d k	S )N)rC   )r   r    r    r!   Úhas_hashÆ   s    zLink.has_hashc             C   sB   |dks| j  rdS | jdk	s"t‚| jdk	s0t‚|j| j| jd�S )zG
        Return True if the link has a hash and it is allowed.
        NF)Z
hex_digest)rM   rC   r.   rB   Úis_hash_allowed)r   Úhashesr    r    r!   rN   Ê   s
    zLink.is_hash_allowed)NNN) Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r%   r&   Úpropertyr   r1   r2   r,   r(   r   r4   r8   ÚreÚcompiler9   r=   r>   r?   rA   rB   rC   rG   rH   rK   rL   rM   rN   Ú__classcell__r    r    )r   r!   r      s8     "

r   )r*   rU   Zpip._vendor.six.moves.urllibr   r   Zpip._internal.utils.miscr   r   r   r   r   Zpip._internal.utils.modelsr   Zpip._internal.utils.typingr	   Útypingr
   r   r   r   Zpip._internal.indexr   Zpip._internal.utils.hashesr   r   r    r    r    r!   Ú<module>   s   