B
    ãUvgž  ã               @   s`   d dl Z d dlZd dlmZ d dlmZ d dlmZ d dl	m
Z
 d dlmZ G dd„ de
ƒZdS )	é    N)Úparse)Úpath_to_url)Úsplitext)ÚKeyBasedCompareMixin)Ú	wheel_extc                   sô   e Zd ZdZd(‡ 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dd„ Zedd„ ƒZedd„ ƒZe d¡Zedd„ ƒZe d¡Zedd„ ƒZe d¡Zedd„ ƒZed d!„ ƒZed"d#„ ƒZed$d%„ ƒZed&d'„ ƒZ‡  ZS ))ÚLinkz?Represents a parsed link from a Package Index's simple URL
    Nc                sF   |  d¡rt|ƒ}|| _|| _|r&|nd| _tt| ƒj| jtd� dS )a¢  
        url:
            url of the resource pointed to (href of the link)
        comes_from:
            instance of HTMLPage where the link was found, or string.
        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.
        z\\N)ÚkeyÚdefining_class)Ú
startswithr   ÚurlÚ
comes_fromÚrequires_pythonÚsuperr   Ú__init__)Úselfr   r   r   )Ú	__class__© ú:/tmp/pip-install-r_9ig3yj/pip/pip/_internal/models/link.pyr      s    

zLink.__init__c             C   s<   | j rd| j  }nd}| jr.d| j| j|f S t| jƒS d S )Nz (requires-python:%s)Ú z%s (from %s)%s)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__3   s    zLink.__repr__c             C   sJ   t  | j¡\}}}}}t | d¡¡p(|}t  |¡}|sFtd| j ƒ‚|S )Nú/zURL %r produced no filename)Úurllib_parseÚurlsplitr   Ú	posixpathÚbasenameÚrstripÚunquoteÚAssertionError)r   Ú_ÚnetlocÚpathÚnamer   r   r   Úfilename6   s
    
zLink.filenamec             C   s   t  | j¡d S )Nr   )r   r   r   )r   r   r   r   Úscheme>   s    zLink.schemec             C   s   t  | j¡d S )Né   )r   r   r   )r   r   r   r   r"   B   s    zLink.netlocc             C   s   t  t  | j¡d ¡S )Né   )r   r   r   r   )r   r   r   r   r#   F   s    z	Link.pathc             C   s   t t | j d¡¡ƒS )Nr   )r   r   r   r#   r   )r   r   r   r   r   J   s    zLink.splitextc             C   s   |   ¡ d S )Nr'   )r   )r   r   r   r   ÚextM   s    zLink.extc             C   s*   t  | j¡\}}}}}t  ||||d f¡S )N)r   r   r   Ú
urlunsplit)r   r&   r"   r#   ÚqueryÚfragmentr   r   r   Úurl_without_fragmentQ   s    zLink.url_without_fragmentz[#&]egg=([^&]*)c             C   s    | j  | j¡}|sd S | d¡S )Nr'   )Ú_egg_fragment_reÚsearchr   Úgroup)r   Úmatchr   r   r   Úegg_fragmentX   s    zLink.egg_fragmentz[#&]subdirectory=([^&]*)c             C   s    | j  | j¡}|sd S | d¡S )Nr'   )Ú_subdirectory_fragment_rer/   r   r0   )r   r1   r   r   r   Úsubdirectory_fragmenta   s    zLink.subdirectory_fragmentz2(sha1|sha224|sha384|sha256|sha512|md5)=([a-f0-9]+)c             C   s    | j  | j¡}|r| d¡S d S )Nr(   )Ú_hash_rer/   r   r0   )r   r1   r   r   r   Úhashl   s    
z	Link.hashc             C   s    | j  | j¡}|r| d¡S d S )Nr'   )r5   r/   r   r0   )r   r1   r   r   r   Ú	hash_names   s    
zLink.hash_namec             C   s$   t  | j dd¡d  dd¡d ¡S )Nú#r'   r   ú?)r   r   r   Úsplit)r   r   r   r   Úshow_urlz   s    zLink.show_urlc             C   s
   | j tkS )N)r)   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)Úpip._internal.vcsr=   r&   Úall_schemes)r   r=   r   r   r   Úis_artifact‚   s    zLink.is_artifact)NN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   Úpropertyr%   r&   r"   r#   r   r)   r-   ÚreÚcompiler.   r2   r3   r4   r5   r6   r7   r;   r<   r@   Ú__classcell__r   r   )r   r   r      s,   


r   )r   rF   Zpip._vendor.six.moves.urllibr   r   Úpip._internal.downloadr   Úpip._internal.utils.miscr   Úpip._internal.utils.modelsr   Úpip._internal.wheelr   r   r   r   r   r   Ú<module>   s   