B
    Qf                 @   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-1jte0t6w/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   