
    vg!                        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 j8                  e      Zee   Zee   Z eegee   f   Z!eege"f   Z# G d	 d
      Z$de%de"fdZ& G d d      Z' G d de$      Z( G d de$      Z) G d de$      Z* G 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Z,y)    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                   @    e Zd Zedee   fd       ZdefdZde	fdZ
y)
LinkSourcereturnc                     t               )z,Returns the underlying link, if there's one.NotImplementedErrorselfs    `/home/mcse/projects/flask/flask-venv/lib/python3.12/site-packages/pip/_internal/index/sources.pylinkzLinkSource.link   s     "##    c                     t               )z9Candidates found by parsing an archive listing HTML file.r   r   s    r   page_candidateszLinkSource.page_candidates#       !##r   c                     t               )z,Links found by specifying archives directly.r   r   s    r   
file_linkszLinkSource.file_links'   r"   r   N)__name__
__module____qualname__propertyr   r   r   FoundCandidatesr!   
FoundLinksr$    r   r   r   r      s7    $htn $ $$ $$J $r   r   file_urlr   c                 <    t        j                  | d      d   dk(  S )NF)strictr   z	text/html)	mimetypes
guess_type)r,   s    r   _is_html_filer1   ,   s    7:kIIr   c                   j    e Zd ZdZdeddfdZd	dZedee   fd       Z	ede
eee   f   fd       Zy)
_FlatDirectoryToUrlsz"Scans directory and caches resultspathr   Nc                 V    || _         g | _        t        t              | _        d| _        y )NF)_path_page_candidatesr   list_project_name_to_urls_scanned_directory)r   r4   s     r   __init__z_FlatDirectoryToUrls.__init__3   s&    
+-;Ft;L""'r   c                    t        j                  | j                        D ]u  }t        |j                        }t        |      r| j                  j                  |       ?	 t        |j                        d   }| j                  |   j                  |       w d| _        y# t        t        f$ r3 	 t        |j                        d   }n# t        t        f$ r Y Y w xY wY iw xY w)zrScans directory once and populates both page_candidates
        and project_name_to_urls at the same time
        r   TN)osscandirr6   r   r4   r1   r7   appendr   namer   r   r   r
   r9   r:   )r   entryurlproject_filenames       r   _scan_directoryz$_FlatDirectoryToUrls._scan_directory9   s     ZZ

+ 	EEejj)CS!%%,,S1#7

#CA#F  &&'78??D!	E" #' ).9 ';EJJ'G'J$,n=  %s6    B  C"0C	C"	CC"CC"!C"c                 R    | j                   s| j                          | j                  S N)r:   rD   r7   r   s    r   r!   z$_FlatDirectoryToUrls.page_candidatesP   s#    &&  "$$$r   c                 R    | j                   s| j                          | j                  S rF   )r:   rD   r9   r   s    r   project_name_to_urlsz)_FlatDirectoryToUrls.project_name_to_urlsW   s#    &&  ")))r   )r   N)r%   r&   r'   __doc__strr;   rD   r(   r   r!   r   rH   r+   r   r   r3   r3   0   sd    ,(S (T ('. %c % % *d3S	>&: * *r   r3   c                   v    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Z
edee   fd	       Zdefd
ZdefdZy)_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_pager4   project_namer   Nc                     || _         t        |      | _        || j                  v r| j                  |   | _        y t        |      | _        | j                  | j                  |<   y )N)r4   )_candidates_from_pager   _project_namerM   _path_to_urlsr3   )r   rN   r4   rO   s       r   r;   z_FlatDirectorySource.__init__j   s_     &:".|< 4&&&!%!4!4T!:D!54!@D(,(:(:D%r   c                      y rF   r+   r   s    r   r   z_FlatDirectorySource.linkz   s    r   c              #      K   | j                   j                  D ]$  }| j                  t        |            E d {    & y 7 wrF   )rS   r!   rQ   r   r   rB   s     r   r!   z$_FlatDirectorySource.page_candidates~   s<     %%55 	=C11$s)<<<	=<s   7AAAc              #   v   K   | j                   j                  | j                     D ]  }t        |        y wrF   )rS   rH   rR   r   rV   s     r   r$   z_FlatDirectorySource.file_links   s5     %%::4;M;MN 	Cs)O	s   79)r%   r&   r'   rI   rM   r   rJ   r3   __annotations__CandidatesFromPager;   r(   r   r   r   r)   r!   r*   r$   r+   r   r   rL   rL   _   s     79ND2238;0; ; 	;
 
;  htn  = =J r   rL   c                   X    e Zd ZdZdededdfdZedee   fd       Z	de
fdZdefd	Zy)
_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.
    rN   r   r   Nc                      || _         || _        y rF   rQ   _linkr   rN   r   s      r   r;   z_LocalFileSource.__init__       
 &:"
r   c                     | j                   S rF   r^   r   s    r   r   z_LocalFileSource.link       zzr   c              #      K   t        | j                  j                        sy | j                  | j                        E d {    y 7 wrF   )r1   r^   rB   rQ   r   s    r   r!   z _LocalFileSource.page_candidates   s1     TZZ^^,--djj999s   ?A	AA	c              #   h   K   t        | j                  j                        ry | j                   y wrF   )r1   r^   rB   r   s    r   r$   z_LocalFileSource.file_links   s#     (jjs   02r%   r&   r'   rI   rY   r   r;   r(   r   r   r)   r!   r*   r$   r+   r   r   r[   r[      s_    0  
	 htn  : :
J r   r[   c                   \    e Zd ZdZdedededdfdZede	e   fd       Z
defd	Zdefd
Zy)_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.
    rN   page_validatorr   r   Nc                 .    || _         || _        || _        y rF   )rQ   _page_validatorr^   )r   rN   ri   r   s       r   r;   z_RemoteFileSource.__init__   s     &:"-
r   c                     | j                   S rF   rb   r   s    r   r   z_RemoteFileSource.link   rc   r   c              #      K   | j                  | j                        sy | j                  | j                        E d {    y 7 wrF   )rk   r^   rQ   r   s    r   r!   z!_RemoteFileSource.page_candidates   s3     ##DJJ/--djj999s   ;AAAc              #   (   K   | j                    y wrF   rb   r   s    r   r$   z_RemoteFileSource.file_links   s     jjs   )r%   r&   r'   rI   rY   PageValidatorr   r;   r(   r   r   r)   r!   r*   r$   r+   r   r   rh   rh      si    0 & 	
 
 htn  : :
J r   rh   c                   X    e Zd ZdZdededdfdZedee   fd       Z	de
fdZdefd	Zy)
_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.
    rN   r   r   Nc                      || _         || _        y rF   r]   r_   s      r   r;   z_IndexDirectorySource.__init__   r`   r   c                     | j                   S rF   rb   r   s    r   r   z_IndexDirectorySource.link   rc   r   c              #   V   K   | j                  | j                        E d {    y 7 wrF   r]   r   s    r   r!   z%_IndexDirectorySource.page_candidates   s     --djj999s   )')c                      y)Nr+   r+   r   s    r   r$   z _IndexDirectorySource.file_links   s    r   rf   r+   r   r   rq   rq      s_    0  
	 htn  : :J r   rq   locationrN   ri   
expand_dircache_link_parsingrO   c                x   d }d }t         j                  j                  |       rt        |       }| }n,| j	                  d      r| }t        |       }nt        |       r| }|d}t        j                  ||        y|t        ||t        ||            }	||	fS t         j                  j                  |      r0|rt        |||      }	||	fS t        |t        ||            }	||	fS t         j                  j                  |      rt        |t        ||            }	||	fS t        j                  d|        |d fS )	Nzfile:zVLocation '%s' is ignored: it is either a non-existing path or lacks a specific scheme.)NN)rx   )rN   ri   r   )rN   r4   rO   )rN   r   z?Location '%s' is ignored: it is neither a file nor a directory.)r=   r4   existsr   
startswithr   r   loggerwarningrh   r   isdirrL   rq   isfiler[   )
rv   rN   ri   rw   rx   rO   r4   rB   msgsources
             r   build_sourcer      sP    DC	ww~~h(#			W	%8$		
{K 	 	sH%|.!5)c.@A

 V}	ww}}T)%9)F V}	 +%9#2DEF V}		!!5c.@A
 V}
NNI ;r   )-loggingr/   r=   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%   r|   r)   r*   rY   boolro   r   rJ   r1   r3   rL   r[   rh   rq   r   r+   r   r   <module>r      s8     	 # B B  A * = $			8	$01d^
tfh/D&EEF $&$ $JC JD J,* ,*^%: %Pz B
 @J 4;; -; "	;
 ; ; ; 8C=(:../;r   