U
    &%e                  	   @   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 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   Z/var/www/html/Darija-Ai-API/env/lib/python3.8/site-packages/pip/_internal/index/sources.pylink   s    zLinkSource.linkc                 C   s
   t  dS )z9Candidates found by parsing an archive listing HTML file.Nr   r   r   r   r   page_candidates   s    zLinkSource.page_candidatesc                 C   s
   t  dS )z,Links found by specifying archives directly.Nr   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 )_FlatDirectorySourcezLink 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t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 r%   r   r   r   r   r   r   8   s    z_FlatDirectorySource.linkc                 c   s>   | j  D ].}tt|}t|s$q
| t|E d H  q
d S r%   )r+   iterdirr   strr!   r&   r   r   r$   urlr   r   r   r   <   s
    z$_FlatDirectorySource.page_candidatesc                 c   s4   | j  D ]$}tt|}t|r$q
t|V  q
d S 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 r%   r&   _linkr   r#   r   r   r   r   r,   U   s    z_LocalFileSource.__init__r   c                 C   s   | j S r%   r6   r   r   r   r   r   ]   s    z_LocalFileSource.linkc                 c   s&   t | jjsd S | | jE d H  d S r%   )r!   r6   r0   r&   r   r   r   r   r   a   s    z _LocalFileSource.page_candidatesc                 c   s   t | jjrd S | jV  d S r%   )r!   r6   r0   r   r   r   r   r   f   s    z_LocalFileSource.file_linksr   r   r   r1   r2   r   r,   r   r   r   r   r   r   r   r   r   r   r   r3   K   s   r3   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 r%   )r&   _page_validatorr6   )r   r#   r;   r   r   r   r   r,   u   s    z_RemoteFileSource.__init__r   c                 C   s   | j S r%   r8   r   r   r   r   r      s    z_RemoteFileSource.linkc                 c   s&   |  | jsd S | | jE d H  d S r%   )r<   r6   r&   r   r   r   r   r      s    z!_RemoteFileSource.page_candidatesc                 c   s   | j V  d S r%   r8   r   r   r   r   r      s    z_RemoteFileSource.file_links)r   r   r   r1   r2   PageValidatorr   r,   r   r   r   r   r   r   r   r   r   r   r   r:   l   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 )_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.
    Nr4   c                 C   s   || _ || _d S r%   r5   r7   r   r   r   r,      s    z_IndexDirectorySource.__init__r   c                 C   s   | j S r%   r8   r   r   r   r   r      s    z_IndexDirectorySource.linkc                 c   s   |  | jE d H  d S r%   r5   r   r   r   r   r      s    z%_IndexDirectorySource.page_candidatesc                 C   s   dS )Nr   r   r   r   r   r   r      s    z _IndexDirectorySource.file_linksr9   r   r   r   r   r>      s   r>   )locationr#   r;   
expand_dircache_link_parsingr   c          	      C   s   d }d }t j| r"t| }| }n$| dr:| }t| }nt| rF| }|d krbd}t||  dS |d krt	||t
||dd}||fS t j|r|rt||d}nt|t
||dd}||fS t j|rt|t
||dd}||fS td|  |d fS )	Nzfile:zVLocation '%s' is ignored: it is either a non-existing path or lacks a specific scheme.)NN)rA   )r#   r;   r   )r#   r$   )r#   r   z?Location '%s' is ignored: it is neither a file nor a directory.)r)   r$   existsr   
startswithr	   r
   loggerwarningr:   r   isdirr"   r>   isfiler3   )	r?   r#   r;   r@   rA   r$   r0   msgsourcer   r   r   build_source   sX    




rJ   )"loggingr   r)   r'   typingr   r   r   r   pip._internal.models.candidater   pip._internal.models.linkr   pip._internal.utils.urlsr   r	   pip._internal.vcsr
   	getLoggerr   rD   r   r   r2   boolr=   r   r.   r!   r"   r3   r:   r>   rJ   r   r   r   r   <module>   s4   
$! 