B
    Kkd                 @   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r|d dlmZ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Text)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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-gxxfd9b7/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\}}}}}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   filename>   s
    
zLink.filenamec             C   s   t | jd S )Nr   )r!   r"   r   )r   r   r   r   schemeG   s    zLink.schemec             C   s   t | jd S )N   )r!   r"   r   )r   r   r   r   r)   L   s    zLink.netlocc             C   s   t t | jd S )N   )r!   r&   r"   r   )r   r   r   r   r*   Q   s    z	Link.pathc             C   s   t t| jdS )Nr    )r   r#   r$   r*   r%   )r   r   r   r   r   V   s    zLink.splitextc             C   s   |   d S )Nr.   )r   )r   r   r   r   extZ   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_fragment_   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_fragmentg   s    zLink.egg_fragmentz[#&]subdirectory=([^&]*)c             C   s    | j | j}|sd S |dS )Nr.   )_subdirectory_fragment_rer6   r   r7   )r   r8   r   r   r   subdirectory_fragmentq   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_rer6   r   r7   )r   r8   r   r   r   hash}   s    
z	Link.hashc             C   s    | j | j}|r|dS d S )Nr.   )r<   r6   r   r7   )r   r8   r   r   r   	hash_name   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_url   s    zLink.show_urlc             C   s
   | j tkS )N)r0   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.vcsrD   r-   all_schemes)r   rD   r   r   r   is_artifact   s    zLink.is_artifact)NN)__name__
__module____qualname____doc__r   r   r   propertyr,   r-   r)   r*   r   r0   r4   recompiler5   r9   r:   r;   r<   r=   r>   rB   rC   rG   __classcell__r   r   )r   r   r      s,   	

r   )r#   rM   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   r   pip._internal.indexr   r   r   r   r   r   <module>   s   