o
    ©„j­!  ã                   @  s>  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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)ÚCallableÚIterable)Ú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   úY/var/www/html/django_cbt/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__4   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   Q   ó   z$_FlatDirectoryToUrls.page_candidatesúdict[str, list[str]]c                 C  r@   rA   )r5   r>   r4   r   r   r   r   Úproject_name_to_urlsX   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.   1   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 )Ú_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.
    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   k   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   `   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   r   Ú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>   s0    

/(! 