U
    cUh!                  
   @   sh  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 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#e$e!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*e$e e"e!e!e$ee
e$ e
e# f dddZ+dS )    N)defaultdict)CallableDictIterableListOptionalTuple)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ee dddZedddZe	dddZ
dS )	
LinkSourcereturnc                 C   s
   t  dS )z,Returns the underlying link, if there's one.NNotImplementedErrorself r   [/opt/bot/vods_filmes/script/venv/lib/python3.8/site-packages/pip/_internal/index/sources.pylink   s    zLinkSource.linkc                 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_candidatesc                 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   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                   @   sb   e Zd ZdZeddddZddddZeee dd	d
Z	ee
eee f dddZdS )_FlatDirectoryToUrlsz"Scans directory and caches resultsN)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__2   s    
z_FlatDirectoryToUrls.__init__r   c                 C   s   t | jD ]}t|j}t|r0| j| qzt|j	d }W nB t
k
r   zt|j	d }W n tk
r~   Y Y qY nX Y nX | 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/   r0   )r   entryurlZproject_filenamer   r   r   _scan_directory8   s    
z$_FlatDirectoryToUrls._scan_directoryc                 C   s   | j s|   | jS N)r0   r8   r-   r   r   r   r   r   O   s    z$_FlatDirectoryToUrls.page_candidatesc                 C   s   | j s|   | jS r9   )r0   r8   r/   r   r   r   r   project_name_to_urlsV   s    z)_FlatDirectoryToUrls.project_name_to_urls)r   r    r!   __doc__strr1   r8   r"   r   r   r   r:   r   r   r   r   r*   /   s   r*   c                   @   sl   e Zd ZU dZi Zeeef ed< e	eeddddZ
eee ddd	Zedd
dZe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.
    _paths_to_urlsN)candidates_from_pager+   project_namer   c                 C   sD   || _ t|| _|| jkr(| j| | _nt|d| _| j| j|< d S )N)r+   )_candidates_from_pager   _project_namer>   _path_to_urlsr*   )r   r?   r+   r@   r   r   r   r1   i   s    

z_FlatDirectorySource.__init__r   c                 C   s   d S r9   r   r   r   r   r   r   y   s    z_FlatDirectorySource.linkc                 c   s&   | j jD ]}| t|E d H  qd S r9   )rC   r   rA   r   r   r7   r   r   r   r   }   s    z$_FlatDirectorySource.page_candidatesc                 c   s"   | j j| j D ]}t|V  qd S r9   )rC   r:   rB   r   rD   r   r   r   r      s    z_FlatDirectorySource.file_links)r   r    r!   r;   r>   r   r<   r*   __annotations__CandidatesFromPager1   r"   r   r   r   r#   r   r$   r   r   r   r   r   r=   ^   s   
r=   c                   @   sT   e Zd ZdZeeddddZeee dddZ	e
dd	d
Ze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.
    Nr?   r   r   c                 C   s   || _ || _d S r9   rA   _linkr   r?   r   r   r   r   r1      s    z_LocalFileSource.__init__r   c                 C   s   | j S r9   rJ   r   r   r   r   r      s    z_LocalFileSource.linkc                 c   s&   t | jjsd S | | jE d H  d S r9   )r)   rJ   r7   rA   r   r   r   r   r      s    z _LocalFileSource.page_candidatesc                 c   s   t | jjrd S | jV  d S r9   )r)   rJ   r7   r   r   r   r   r      s    z_LocalFileSource.file_linksr   r    r!   r;   rF   r   r1   r"   r   r   r#   r   r$   r   r   r   r   r   rG      s   rG   c                   @   sV   e Zd ZdZeeeddddZee	e dddZ
edd	d
Ze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.
    N)r?   page_validatorr   r   c                 C   s   || _ || _|| _d S r9   )rA   _page_validatorrJ   )r   r?   rO   r   r   r   r   r1      s    z_RemoteFileSource.__init__r   c                 C   s   | j S r9   rL   r   r   r   r   r      s    z_RemoteFileSource.linkc                 c   s&   |  | jsd S | | jE d H  d S r9   )rP   rJ   rA   r   r   r   r   r      s    z!_RemoteFileSource.page_candidatesc                 c   s   | j V  d S r9   rL   r   r   r   r   r      s    z_RemoteFileSource.file_links)r   r    r!   r;   rF   PageValidatorr   r1   r"   r   r   r#   r   r$   r   r   r   r   r   rN      s   

rN   c                   @   sT   e Zd ZdZeeddddZeee dddZ	e
dd	d
Ze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.
    NrH   c                 C   s   || _ || _d S r9   rI   rK   r   r   r   r1      s    z_IndexDirectorySource.__init__r   c                 C   s   | j S r9   rL   r   r   r   r   r      s    z_IndexDirectorySource.linkc                 c   s   |  | jE d H  d S r9   rI   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_linksrM   r   r   r   r   rR      s   rR   )locationr?   rO   
expand_dircache_link_parsingr@   r   c          
      C   s   d }d }t j| r"t| }| }n$| dr:| }t| }nt| rF| }|d krbd}t||  dS |d krt	||t
||dd}	||	fS t j|r|rt|||d}	nt|t
||dd}	||	fS t j|rt|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?   rO   r   )r?   r+   r@   )r?   r   z?Location '%s' is ignored: it is neither a file nor a directory.)r2   r+   existsr   
startswithr   r   loggerwarningrN   r   isdirr=   rR   isfilerG   )
rS   r?   rO   rT   rU   r@   r+   r7   msgsourcer   r   r   build_source   sZ    	




r^   ),loggingr'   r2   collectionsr   typingr   r   r   r   r   r   pip._vendor.packaging.utilsr	   r
   r   r   r   Zpip._internal.models.candidater   pip._internal.models.linkr   pip._internal.utils.urlsr   r   pip._internal.vcsr   	getLoggerr   rX   r#   r$   rF   boolrQ   r   r<   r)   r*   r=   rG   rN   rR   r^   r   r   r   r   <module>   s:    
/(! 