o
    h                     @   s<  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d	ed
ef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 dededededed
eee ee f f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dee fddZdefddZde	fddZ
dS )	
LinkSourcereturnc                 C      t  )z,Returns the underlying link, if there's one.NotImplementedErrorself r   W/var/www/html/olx_land/venv/lib/python3.10/site-packages/pip/_internal/index/sources.pylink   s   zLinkSource.linkc                 C   r   )z9Candidates found by parsing an archive listing HTML file.r   r   r   r   r   page_candidates      zLinkSource.page_candidatesc                 C   r   )z,Links found by specifying archives directly.r   r   r   r   r   
file_links   r   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                   @   sX   e Zd ZdZdededdfddZedee	 fdd	Z
defd
dZdef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.
    candidates_from_pagepathr   Nc                 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__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   s6    | j  D ]}tt|}t|rqt|V  qd S r&   )r,   r.   r   r/   r"   r   r0   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                   @   X   e Zd ZdZdededdfddZedee fdd	Z	de
fd
dZdef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.
    r$   r   r   Nc                 C      || _ || _d S r&   r'   _linkr   r$   r   r   r   r   r-   U      
z_LocalFileSource.__init__c                 C      | j S r&   r8   r   r   r   r   r   ]   r   z_LocalFileSource.linkc                 c   s(    t | jjs	d S | | jE d H  d S r&   )r"   r8   r1   r'   r   r   r   r   r   a      z _LocalFileSource.page_candidatesc                 c   s    t | jjr	d S | jV  d S r&   )r"   r8   r1   r   r   r   r   r   f   s   z_LocalFileSource.file_linksr   r   r   r2   r3   r   r-   r   r   r   r   r   r   r   r   r   r   r   r5   K   s    	
r5   c                   @   s\   e Zd ZdZdedededdfddZede	e fd	d
Z
defddZdef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.
    r$   page_validatorr   r   Nc                 C   s   || _ || _|| _d S r&   )r'   _page_validatorr8   )r   r$   r@   r   r   r   r   r-   u   s   
z_RemoteFileSource.__init__c                 C   r;   r&   r<   r   r   r   r   r      r   z_RemoteFileSource.linkc                 c   s(    |  | js	d S | | jE d H  d S r&   )rA   r8   r'   r   r   r   r   r      r=   z!_RemoteFileSource.page_candidatesc                 c   s    | j V  d S r&   r<   r   r   r   r   r      s   z_RemoteFileSource.file_links)r   r   r   r2   r3   PageValidatorr   r-   r   r   r   r   r   r   r   r   r   r   r   r?   l   s    

r?   c                   @   r4   )_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.
    r$   r   r   Nc                 C   r6   r&   r7   r9   r   r   r   r-      r:   z_IndexDirectorySource.__init__c                 C   r;   r&   r<   r   r   r   r   r      r   z_IndexDirectorySource.linkc                 c   s    |  | jE d H  d S r&   r7   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_linksr>   r   r   r   r   rC      s    
rC   locationr$   r@   
expand_dircache_link_parsingc          	      C   s  d }d }t j| rt| }| }n| dr| }t| }nt| r#| }|d u r1d}t||  dS |d u rDt	||t
||dd}||fS t j|rd|rVt||d}||fS t|t
||dd}||fS t j|rxt|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)rF   )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#   rC   isfiler5   )	rD   r$   r@   rE   rF   r%   r1   msgsourcer   r   r   build_source   sZ   	


	

rO   )"loggingr    r*   r(   typingr   r   r   r   pip._internal.models.candidater   pip._internal.models.linkr   pip._internal.utils.urlsr   r	   pip._internal.vcsr
   	getLoggerr   rI   r   r   r3   boolrB   r   r/   r"   r#   r5   r?   rC   rO   r   r   r   r   <module>   sB    
$! 