o
    h!                     @  sF  d dl mZ d dlZ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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(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)d&d'Z)dS )*    )annotationsN)defaultdict)Iterable)Callable)InvalidSdistFilename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ddZdddZdd	d
ZdS )
LinkSourcereturnLink | Nonec                 C     t  )z,Returns the underlying link, if there's one.NotImplementedErrorself r   N/var/www/html/venv/lib/python3.10/site-packages/pip/_internal/index/sources.pylink    s   zLinkSource.linkFoundCandidatesc                 C  r   )z9Candidates found by parsing an archive listing HTML file.r   r   r   r   r   page_candidates%      zLinkSource.page_candidates
FoundLinksc                 C  r   )z,Links found by specifying archives directly.r   r   r   r   r   
file_links)   r   zLinkSource.file_linksNr   r   r   r   r   r   )__name__
__module____qualname__propertyr   r   r   r   r   r   r   r      s
    
r   file_urlstrr   boolc                 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ddZddd	ZedddZedddZdS )_FlatDirectoryToUrlsz"Scans directory and caches resultspathr(   r   Nonec                 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__5   s   

z_FlatDirectoryToUrls.__init__c                 C  s   t | jD ]A}t|j}t|r| j| qz	t|j	d }W n t
y>   z	t|j	d }W n
 t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scandirr1   r   r/   r-   r2   appendr
   namer   r	   r   r4   r5   )r   entryurlproject_filenamer   r   r   _scan_directory;   s"   

z$_FlatDirectoryToUrls._scan_directory	list[str]c                 C     | j s|   | jS N)r5   r>   r2   r   r   r   r   r   R      z$_FlatDirectoryToUrls.page_candidatesdict[str, list[str]]c                 C  r@   rA   )r5   r>   r4   r   r   r   r   project_name_to_urlsY   rB   z)_FlatDirectoryToUrls.project_name_to_urlsN)r/   r(   r   r0   )r   r0   )r   r?   )r   rC   )	r#   r$   r%   __doc__r6   r>   r&   r   rD   r   r   r   r   r.   2   s    

r.   c                   @  sJ   e Zd ZU dZi Zded< dddZedddZdddZ	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.
    zdict[str, _FlatDirectoryToUrls]_paths_to_urlscandidates_from_pageCandidatesFromPager/   r(   project_namer   r0   c                 C  sF   || _ t|| _|| jv r| j| | _d S t|d| _| j| j|< d S )N)r/   )_candidates_from_pager   _project_namerG   _path_to_urlsr.   )r   rH   r/   rJ   r   r   r   r6   l   s   

z_FlatDirectorySource.__init__r   c                 C  s   d S rA   r   r   r   r   r   r   |   s   z_FlatDirectorySource.linkr   c                 c  s(    | j jD ]}| t|E d H  qd S rA   )rM   r   rK   r   r   r<   r   r   r   r      s   z$_FlatDirectorySource.page_candidatesr   c                 c  s$    | j j| j D ]}t|V  qd S rA   )rM   rD   rL   r   rN   r   r   r   r      s   z_FlatDirectorySource.file_linksN)rH   rI   r/   r(   rJ   r(   r   r0   r    r!   r"   )r#   r$   r%   rE   rG   __annotations__r6   r&   r   r   r   r   r   r   r   rF   a   s   
 

rF   c                   @  <   e Zd ZdZddd	ZedddZdddZ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.
    rH   rI   r   r   r   r0   c                 C     || _ || _d S rA   rK   _linkr   rH   r   r   r   r   r6         
z_LocalFileSource.__init__r   c                 C     | j S rA   rT   r   r   r   r   r      r   z_LocalFileSource.linkr   c                 c  s(    t | jjs	d S | | jE d H  d S rA   )r-   rT   r<   rK   r   r   r   r   r         z _LocalFileSource.page_candidatesr   c                 c  s    t | jjr	d S | jV  d S rA   )r-   rT   r<   r   r   r   r   r      s   z_LocalFileSource.file_linksNrH   rI   r   r   r   r0   r    r!   r"   	r#   r$   r%   rE   r6   r&   r   r   r   r   r   r   r   rQ      s    
	
rQ   c                   @  s<   e Zd ZdZdd
dZedddZdddZ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.
    rH   rI   page_validatorPageValidatorr   r   r   r0   c                 C  s   || _ || _|| _d S rA   )rK   _page_validatorrT   )r   rH   r]   r   r   r   r   r6      s   
z_RemoteFileSource.__init__r   c                 C  rW   rA   rX   r   r   r   r   r      r   z_RemoteFileSource.linkr   c                 c  s(    |  | js	d S | | jE d H  d S rA   )r_   rT   rK   r   r   r   r   r      rY   z!_RemoteFileSource.page_candidatesr   c                 c  s    | j V  d S rA   rX   r   r   r   r   r      s   z_RemoteFileSource.file_linksN)rH   rI   r]   r^   r   r   r   r0   r    r!   r"   r[   r   r   r   r   r\      s    


r\   c                   @  rP   )_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.
    rH   rI   r   r   r   r0   c                 C  rR   rA   rS   rU   r   r   r   r6      rV   z_IndexDirectorySource.__init__r   c                 C  rW   rA   rX   r   r   r   r   r      r   z_IndexDirectorySource.linkr   c                 c  s    |  | jE d H  d S rA   rS   r   r   r   r   r      s   z%_IndexDirectorySource.page_candidatesr   c                 C  s   dS )Nr   r   r   r   r   r   r      s   z _IndexDirectorySource.file_linksNrZ   r    r!   r"   r[   r   r   r   r   r`      s    

r`   locationrH   rI   r]   r^   
expand_dircache_link_parsingrJ   $tuple[str | None, LinkSource | None]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)rc   )rH   r]   r   )rH   r/   rJ   )rH   r   z?Location '%s' is ignored: it is neither a file nor a directory.)r7   r/   existsr   
startswithr   r   loggerwarningr\   r   isdirrF   r`   isfilerQ   )
ra   rH   r]   rb   rc   rJ   r/   r<   msgsourcer   r   r   build_source   s\   	





rm   )r'   r(   r   r)   )ra   r(   rH   rI   r]   r^   rb   r)   rc   r)   rJ   r(   r   rd   )*
__future__r   loggingr+   r7   collectionsr   collections.abcr   typingr   pip._vendor.packaging.utilsr   r   r   r	   r
   pip._internal.models.candidater   pip._internal.models.linkr   pip._internal.utils.urlsr   r   pip._internal.vcsr   	getLoggerr#   rg   r   r   rI   r)   r^   r   r-   r.   rF   rQ   r\   r`   rm   r   r   r   r   <module>   s2    

/(! 