3
#+]                 @   s   d dl Z d dlZd dlmZ d dlmZ d dlmZm	Z	m
Z
 d dlmZ d dlmZ erxd dlmZmZmZ d dlmZ G d	d
 d
eZdS )    N)parse)path_to_url)WHEEL_EXTENSIONredact_password_from_urlsplitext)KeyBasedCompareMixin)MYPY_CHECK_RUNNING)OptionalTupleUnion)HTMLPagec                   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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  ZS ))Linkz?Represents a parsed link from a Package Index's simple URL
    Nc                sF   |j 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-652y2hkr/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__0   s    
zLink.__str__c             C   s   d|  S )Nz	<Link %s>r   )r   r   r   r   __repr__;   s    zLink.__repr__c             C   sJ   t j| j\}}}}}tj|jdp(|}t j|}|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   filename>   s
    
zLink.filenamec             C   s   t j| jd S )Nr   )r    r!   r   )r   r   r   r   schemeG   s    zLink.schemec             C   s   t j| jd S )N   )r    r!   r   )r   r   r   r   r(   L   s    zLink.netlocc             C   s   t jt j| jd S )N   )r    r%   r!   r   )r   r   r   r   r)   Q   s    z	Link.pathc             C   s   t tj| jjdS )Nr   )r   r"   r#   r)   r$   )r   r   r   r   r   V   s    zLink.splitextc             C   s   | j  d S )Nr-   )r   )r   r   r   r   extZ   s    zLink.extc             C   s*   t j| j\}}}}}t j||||d fS )N)r    r!   r   
urlunsplit)r   r,   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 )Nr-   )_egg_fragment_researchr   group)r   matchr   r   r   egg_fragmentg   s    zLink.egg_fragmentz[#&]subdirectory=([^&]*)c             C   s    | j j| j}|sd S |jdS )Nr-   )_subdirectory_fragment_rer5   r   r6   )r   r7   r   r   r   subdirectory_fragmentq   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 )Nr.   )_hash_rer5   r   r6   )r   r7   r   r   r   hash}   s    
z	Link.hashc             C   s    | j j| j}|r|jdS d S )Nr-   )r;   r5   r   r6   )r   r7   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#r-   r   ?)r"   r#   r   split)r   r   r   r   show_url   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.vcsrC   r,   all_schemes)r   rC   r   r   r   is_artifact   s    zLink.is_artifact)NN)__name__
__module____qualname____doc__r   r   r   propertyr+   r,   r(   r)   r   r/   r3   recompiler4   r8   r9   r:   r;   r<   r=   rA   rB   rF   __classcell__r   r   )r   r   r      s,   	

r   )r"   rL   pip._vendor.six.moves.urllibr   r    pip._internal.downloadr   pip._internal.utils.miscr   r   r   pip._internal.utils.modelsr   pip._internal.utils.typingr   typingr	   r
   r   pip._internal.indexr   r   r   r   r   r   <module>   s   