a
    ñ»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 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œ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dddd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d„ƒZddœdd„Zddœd	d
„ZdS )Ú
LinkSourceúLink | None©Úreturnc                 C  s
   t ƒ ‚dS )z,Returns the underlying link, if there's one.N©ÚNotImplementedError©Úself© r   úAE:\soccer\ml_env\Lib\site-packages\pip/_internal/index/sources.pyÚlink    s    zLinkSource.linkÚFoundCandidatesc                 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_candidatesÚ
FoundLinksc                 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   r   r   r   r   r      s   r   ÚstrÚbool)Ú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                   @  sR   e Zd ZdZdddœdd„Zddœdd	„Zed
dœdd„ƒZeddœdd„ƒZdS )Ú_FlatDirectoryToUrlsz"Scans directory and caches resultsr#   ÚNone)Úpathr   c                 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__r   c                 C  sž   t  | j¡D ]†}t|jƒ}t|ƒr0| j |¡ qzt|j	ƒd }W n> t
y€   zt|j	ƒd }W n tyz   Y Y qY n0 Y n0 | 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   r0   r1   )r   ÚentryÚurlZproject_filenamer   r   r   Ú_scan_directory;   s    
z$_FlatDirectoryToUrls._scan_directoryz	list[str]c                 C  s   | j s|  ¡  | jS ©N)r1   r9   r.   r   r   r   r   r   R   s    z$_FlatDirectoryToUrls.page_candidateszdict[str, list[str]]c                 C  s   | j s|  ¡  | jS r:   )r1   r9   r0   r   r   r   r   Úproject_name_to_urlsY   s    z)_FlatDirectoryToUrls.project_name_to_urlsN)	r   r    r!   Ú__doc__r2   r9   r"   r   r;   r   r   r   r   r*   2   s   r*   c                   @  s`   e Zd ZU dZi Zded< dddddœdd	„Zed
dœdd„ƒZddœdd„Z	d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ÚCandidatesFromPager#   r+   )Úcandidates_from_pager,   Úproject_namer   c                 C  sD   || _ t|ƒ| _|| jv r(| j| | _nt|d�| _| j| j|< d S )N)r,   )Ú_candidates_from_pager   Ú_project_namer>   Ú_path_to_urlsr*   )r   r@   r,   rA   r   r   r   r2   l   s    

z_FlatDirectorySource.__init__r   r   c                 C  s   d S r:   r   r   r   r   r   r   |   s    z_FlatDirectorySource.linkr   c                 c  s&   | j jD ]}|  t|ƒ¡E d H  qd S r:   )rD   r   rB   r   ©r   r8   r   r   r   r   €   s    z$_FlatDirectorySource.page_candidatesr   c                 c  s"   | j j| j D ]}t|ƒV  qd S r:   )rD   r;   rC   r   rE   r   r   r   r   „   s    z_FlatDirectorySource.file_linksN)r   r    r!   r<   r>   Ú__annotations__r2   r"   r   r   r   r   r   r   r   r=   a   s   
r=   c                   @  sP   e Zd ZdZddddœdd„Zedd	œd
d„ƒZdd	œdd„Zd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.
    r?   r   r+   ©r@   r   r   c                 C  s   || _ || _d S r:   ©rB   Ú_link©r   r@   r   r   r   r   r2   “   s    z_LocalFileSource.__init__r   r   c                 C  s   | j S r:   ©rJ   r   r   r   r   r   ›   s    z_LocalFileSource.linkr   c                 c  s&   t | jjƒsd S |  | j¡E d H  d S r:   )r)   rJ   r8   rB   r   r   r   r   r   Ÿ   s    z _LocalFileSource.page_candidatesr   c                 c  s   t | jjƒrd S | jV  d S r:   )r)   rJ   r8   r   r   r   r   r   ¤   s    z_LocalFileSource.file_linksN©	r   r    r!   r<   r2   r"   r   r   r   r   r   r   r   rG   ‰   s   	rG   c                   @  sR   e Zd ZdZdddddœdd„Zed	d
œdd„ƒZdd
œdd„Zd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.
    r?   ÚPageValidatorr   r+   )r@   Úpage_validatorr   r   c                 C  s   || _ || _|| _d S r:   )rB   Ú_page_validatorrJ   )r   r@   rP   r   r   r   r   r2   ³   s    z_RemoteFileSource.__init__r   r   c                 C  s   | j S r:   rL   r   r   r   r   r   ½   s    z_RemoteFileSource.linkr   c                 c  s&   |   | j¡sd S |  | j¡E d H  d S r:   )rQ   rJ   rB   r   r   r   r   r   Á   s    z!_RemoteFileSource.page_candidatesr   c                 c  s   | j V  d S r:   rL   r   r   r   r   r   Æ   s    z_RemoteFileSource.file_linksNrM   r   r   r   r   rN   ª   s   
rN   c                   @  sP   e Zd ZdZddddœdd„Zedd	œd
d„ƒZdd	œdd„Zd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.
    r?   r   r+   rH   c                 C  s   || _ || _d S r:   rI   rK   r   r   r   r2   Ñ   s    z_IndexDirectorySource.__init__r   r   c                 C  s   | j S r:   rL   r   r   r   r   r   Ù   s    z_IndexDirectorySource.linkr   c                 c  s   |   | j¡E d H  d S r:   rI   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_linksNrM   r   r   r   r   rR   Ê   s   rR   r?   rO   z$tuple[str | None, LinkSource | None])Úlocationr@   rP   Ú
expand_dirÚcache_link_parsingrA   r   c          
      C  s   d }d }t j | ¡r"t| ƒ}| }n$|  d¡r:| }t| ƒ}nt| ƒrF| }|d u rbd}t || ¡ dS |d u rˆt	||t
||d�d�}	||	fS t j |¡rÄ|r¨t|||d�}	nt|t
||d�d�}	||	fS t j |¡rìt|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)rU   )r@   rP   r   )r@   r,   rA   )r@   r   z?Location '%s' is ignored: it is neither a file nor a directory.)r3   r,   Úexistsr   Ú
startswithr   r   ÚloggerÚwarningrN   r   Úisdirr=   rR   ÚisfilerG   )
rS   r@   rP   rT   rU   rA   r,   r8   ÚmsgÚsourcer   r   r   Úbuild_sourceä   sZ    	

ÿ
ýý
þ
þþr^   )*Ú
__future__r   Úloggingr'   r3   Ú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   rX   r   r   r?   r$   rO   r   r)   r*   r=   rG   rN   rR   r^   r   r   r   r   Ú<module>   s0   
/(! 