3
ûâde�  ã            	   @   s0  d dl Z d dlZd dlZd dlZd dlmZmZmZmZ d dl	m
Z
 d dlmZ d dlmZmZ d dlmZ e jeƒZee
 Zee Zeegee
 f Zeegef ZG dd„ dƒZeed	œd
d„ZG dd„ deƒZG dd„ deƒZG dd„ deƒZG dd„ deƒZ eeeeeeee ee f dœdd„Z!dS )é    N)ÚCallableÚIterableÚOptionalÚTuple)ÚInstallationCandidate)ÚLink)Úpath_to_urlÚurl_to_path)Úis_urlc               @   s>   e Zd Zeee dœdd„ƒZedœdd„Ze	dœdd„Z
dS )	Ú
LinkSource)Úreturnc             C   s
   t ƒ ‚dS )z,Returns the underlying link, if there's one.N)ÚNotImplementedError)Úself© r   ú:/tmp/pip-build-red6nood/pip/pip/_internal/index/sources.pyÚlink   s    zLinkSource.linkc             C   s
   t ƒ ‚dS )z9Candidates found by parsing an archive listing HTML file.N)r   )r   r   r   r   Úpage_candidates   s    zLinkSource.page_candidatesc             C   s
   t ƒ ‚dS )z,Links found by specifying archives directly.N)r   )r   r   r   r   Ú
file_links   s    zLinkSource.file_linksN)Ú__name__Ú
__module__Ú__qualname__Úpropertyr   r   r   ÚFoundCandidatesr   Ú
FoundLinksr   r   r   r   r   r      s   r   )Úfile_urlr   c             C   s   t j| dd�d dkS )NF)Ústrictr   z	text/html)Ú	mimetypesÚ
guess_type)r   r   r   r   Ú_is_html_file#   s    r   c               @   sT   e Zd ZdZeeddœdd„Zeee	 dœdd„ƒZ
edœd	d
„Zedœdd„ZdS )Ú_FlatDirectorySourcezûLink source specified by ``--find-links=<path-to-dir>``.

    This looks the content of the directory, and returns:

    * ``page_candidates``: Links listed on each HTML file in the directory.
    * ``file_candidates``: Archives in the directory.
    N)Úcandidates_from_pageÚpathr   c             C   s   || _ tjtjj|ƒƒ| _d S )N)Ú_candidates_from_pageÚpathlibÚPathÚosr!   ÚrealpathÚ_path)r   r    r!   r   r   r   Ú__init__0   s    z_FlatDirectorySource.__init__)r   c             C   s   d S )Nr   )r   r   r   r   r   8   s    z_FlatDirectorySource.linkc             c   sB   x<| j jƒ D ].}tt|ƒƒ}t|ƒs&q| jt|ƒƒE d H  qW d S )N)r'   Úiterdirr   Ústrr   r"   r   )r   r!   Úurlr   r   r   r   <   s
    z$_FlatDirectorySource.page_candidatesc             c   s8   x2| j jƒ D ]$}tt|ƒƒ}t|ƒr&qt|ƒV  qW d S )N)r'   r)   r   r*   r   r   )r   r!   r+   r   r   r   r   C   s
    z_FlatDirectorySource.file_links)r   r   r   Ú__doc__ÚCandidatesFromPager*   r(   r   r   r   r   r   r   r   r   r   r   r   r   r   '   s   r   c               @   sT   e Zd ZdZeeddœdd„Zeee dœdd„ƒZ	e
dœd	d
„Zedœdd„ZdS )Ú_LocalFileSourceaC  ``--find-links=<path-or-url>`` or ``--[extra-]index-url=<path-or-url>``.

    If a URL is supplied, it must be a ``file:`` URL. If a path is supplied to
    the option, it is converted to a URL first. This returns:

    * ``page_candidates``: Links listed on an HTML file.
    * ``file_candidates``: The non-HTML file.
    N)r    r   r   c             C   s   || _ || _d S )N)r"   Ú_link)r   r    r   r   r   r   r(   U   s    z_LocalFileSource.__init__)r   c             C   s   | j S )N)r/   )r   r   r   r   r   ]   s    z_LocalFileSource.linkc             c   s&   t | jjƒsd S | j| jƒE d H  d S )N)r   r/   r+   r"   )r   r   r   r   r   a   s    z _LocalFileSource.page_candidatesc             c   s   t | jjƒrd S | jV  d S )N)r   r/   r+   )r   r   r   r   r   f   s    z_LocalFileSource.file_links)r   r   r   r,   r-   r   r(   r   r   r   r   r   r   r   r   r   r   r   r.   K   s   r.   c               @   sV   e Zd ZdZeeeddœdd„Zee	e dœdd„ƒZ
edœd	d
„Zedœdd„ZdS )Ú_RemoteFileSourcez¸``--find-links=<url>`` or ``--[extra-]index-url=<url>``.

    This returns:

    * ``page_candidates``: Links listed on an HTML file.
    * ``file_candidates``: The non-HTML file.
    N)r    Úpage_validatorr   r   c             C   s   || _ || _|| _d S )N)r"   Ú_page_validatorr/   )r   r    r1   r   r   r   r   r(   u   s    z_RemoteFileSource.__init__)r   c             C   s   | j S )N)r/   )r   r   r   r   r      s    z_RemoteFileSource.linkc             c   s&   | j | jƒsd S | j| jƒE d H  d S )N)r2   r/   r"   )r   r   r   r   r   ƒ   s    z!_RemoteFileSource.page_candidatesc             c   s   | j V  d S )N)r/   )r   r   r   r   r   ˆ   s    z_RemoteFileSource.file_links)r   r   r   r,   r-   ÚPageValidatorr   r(   r   r   r   r   r   r   r   r   r   r   r   r0   l   s   r0   c               @   sT   e Zd ZdZeeddœdd„Zeee dœdd„ƒZ	e
dœd	d
„Zedœdd„ZdS )Ú_IndexDirectorySourcez·``--[extra-]index-url=<path-to-directory>``.

    This is treated like a remote URL; ``candidates_from_page`` contains logic
    for this by appending ``index.html`` to the link.
    N)r    r   r   c             C   s   || _ || _d S )N)r"   r/   )r   r    r   r   r   r   r(   “   s    z_IndexDirectorySource.__init__)r   c             C   s   | j S )N)r/   )r   r   r   r   r   ›   s    z_IndexDirectorySource.linkc             c   s   | j | jƒE d H  d S )N)r"   r/   )r   r   r   r   r   Ÿ   s    z%_IndexDirectorySource.page_candidatesc             C   s   f S )Nr   )r   r   r   r   r   ¢   s    z _IndexDirectorySource.file_links)r   r   r   r,   r-   r   r(   r   r   r   r   r   r   r   r   r   r   r   r4   Œ   s   r4   )Úlocationr    r1   Ú
expand_dirÚcache_link_parsingr   c      	      C   sþ   d }d }t jj| ƒr"t| ƒ}| }n$| jdƒr:| }t| ƒ}nt| ƒrF| }|d krbd}tj|| ƒ dS |d krˆt	||t
||d�d�}||fS t jj|ƒrÂ|r¦t||d�}nt|t
||d�d�}||fS t jj|ƒrêt|t
||d�d�}||fS tjd| ƒ |d fS )	Nzfile:zVLocation '%s' is ignored: it is either a non-existing path or lacks a specific scheme.)r7   )r    r1   r   )r    r!   )r    r   z?Location '%s' is ignored: it is neither a file nor a directory.)NN)r%   r!   Úexistsr   Ú
startswithr	   r
   ÚloggerÚwarningr0   r   Úisdirr   r4   Úisfiler.   )	r5   r    r1   r6   r7   r!   r+   ÚmsgÚsourcer   r   r   Úbuild_source¦   sL    	


r@   )"Úloggingr   r%   r#   Útypingr   r   r   r   Zpip._internal.models.candidater   Zpip._internal.models.linkr   Zpip._internal.utils.urlsr   r	   Zpip._internal.vcsr
   Ú	getLoggerr   r:   r   r   r-   Úboolr3   r   r*   r   r   r.   r0   r4   r@   r   r   r   r   Ú<module>   s2   
$! 