o
    f!                     @   sz  d dl Z d dlZd dlZd dlmZ d dlmZmZmZm	Z	m
Z
mZ d dlmZmZ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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%dee
e% e
e$ f fdd Z,dS )!    N)defaultdict)CallableDictIterableListOptionalTuple)InvalidSdistFilenameInvalidVersionInvalidWheelFilenamecanonicalize_nameparse_sdist_filenameparse_wheel_filename)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/mig_web/myenv/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                   @   s`   e Zd ZdZdeddfddZdddZedee fd	d
Z	ede
eee f fddZdS )_FlatDirectoryToUrlsz"Scans directory and caches resultspathr   Nc                 C   s    || _ g | _tt| _d| _d S )NF)_path_page_candidatesr   list_project_name_to_urls_scanned_directory)r   r-   r   r   r   __init__3   s   

z_FlatDirectoryToUrls.__init__c                 C   s   t | jD ]E}t|j}t|r| j| qz	t|j	d }W n! t
tfyB   z	t|j	d }W n ttfy?   Y Y qw Y nw | j| | qd| _dS )zrScans directory once and populates both page_candidates
        and project_name_to_urls at the same time
        r   TN)osscandirr.   r   r-   r+   r/   appendr   namer   r
   r   r	   r1   r2   )r   entryurlproject_filenamer   r   r   _scan_directory9   s"   

z$_FlatDirectoryToUrls._scan_directoryc                 C      | j s|   | jS N)r2   r;   r/   r   r   r   r   r   P      z$_FlatDirectoryToUrls.page_candidatesc                 C   r<   r=   )r2   r;   r1   r   r   r   r   project_name_to_urlsW   r>   z)_FlatDirectoryToUrls.project_name_to_urls)r   N)r!   r"   r#   __doc__strr3   r;   r$   r   r   r   r?   r   r   r   r   r,   0   s    
 r,   c                   @   sr   e Zd ZU dZi Zeeef ed< 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 )_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.
    _paths_to_urlscandidates_from_pager-   project_namer   Nc                 C   sF   || _ t|| _|| jv r| j| | _d S t|d| _| j| j|< d S )N)r-   )_candidates_from_pager   _project_namerC   _path_to_urlsr,   )r   rD   r-   rE   r   r   r   r3   j   s   

z_FlatDirectorySource.__init__c                 C   s   d S r=   r   r   r   r   r   r   z   s   z_FlatDirectorySource.linkc                 c   s(    | j jD ]}| t|E d H  qd S r=   )rH   r   rF   r   r   r9   r   r   r   r   ~   s   z$_FlatDirectorySource.page_candidatesc                 c   s$    | j j| j D ]}t|V  qd S r=   )rH   r?   rG   r   rI   r   r   r   r       s   z_FlatDirectorySource.file_links)r!   r"   r#   r@   rC   r   rA   r,   __annotations__CandidatesFromPager3   r$   r   r   r   r%   r   r&   r    r   r   r   r   rB   _   s    
 
rB   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.
    rD   r   r   Nc                 C      || _ || _d S r=   rF   _linkr   rD   r   r   r   r   r3         
z_LocalFileSource.__init__c                 C      | j S r=   rP   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+   rP   r9   rF   r   r   r   r   r         z _LocalFileSource.page_candidatesc                 c   s    t | jjr	d S | jV  d S r=   )r+   rP   r9   r   r   r   r   r       s   z_LocalFileSource.file_linksr!   r"   r#   r@   rK   r   r3   r$   r   r   r%   r   r&   r    r   r   r   r   rM      s    	
rM   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.
    rD   page_validatorr   r   Nc                 C   s   || _ || _|| _d S r=   )rF   _page_validatorrP   )r   rD   rX   r   r   r   r   r3      s   
z_RemoteFileSource.__init__c                 C   rS   r=   rT   r   r   r   r   r      r   z_RemoteFileSource.linkc                 c   s(    |  | js	d S | | jE d H  d S r=   )rY   rP   rF   r   r   r   r   r      rU   z!_RemoteFileSource.page_candidatesc                 c   s    | j V  d S r=   rT   r   r   r   r   r       s   z_RemoteFileSource.file_links)r!   r"   r#   r@   rK   PageValidatorr   r3   r$   r   r   r%   r   r&   r    r   r   r   r   rW      s    

rW   c                   @   rL   )_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.
    rD   r   r   Nc                 C   rN   r=   rO   rQ   r   r   r   r3      rR   z_IndexDirectorySource.__init__c                 C   rS   r=   rT   r   r   r   r   r      r   z_IndexDirectorySource.linkc                 c   s    |  | jE d H  d S r=   rO   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_linksrV   r   r   r   r   r[      s    
r[   locationrD   rX   
expand_dircache_link_parsingrE   c          
      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|re|rWt|||d}	||	fS t|t
||dd}	||	fS t j|ryt|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)r^   )rD   rX   r   )rD   r-   rE   )rD   r   z?Location '%s' is ignored: it is neither a file nor a directory.)r4   r-   existsr   
startswithr   r   loggerwarningrW   r   isdirrB   r[   isfilerM   )
r\   rD   rX   r]   r^   rE   r-   r9   msgsourcer   r   r   build_source   s\   	





rg   )-loggingr)   r4   collectionsr   typingr   r   r   r   r   r   pip._vendor.packaging.utilsr	   r
   r   r   r   r   pip._internal.models.candidater   pip._internal.models.linkr   pip._internal.utils.urlsr   r   pip._internal.vcsr   	getLoggerr!   ra   r%   r&   rK   boolrZ   r   rA   r+   r,   rB   rM   rW   r[   rg   r   r   r   r   <module>   sJ      	
/(! 