
    
i                     `   d dl mZ d dlZd dlZd dlZd dl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 d dl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m Z m!Z!m"Z" d dl#m$Z$ d dl%m&Z& d dl'm(Z( d dl)m*Z*m+Z+ ddl,m-Z-m.Z.m/Z/m0Z0  G d dejb                  jd                        Z3 G d de      Z2y)    )annotationsN)
CollectionIterableIteratorMappingSequence)PathLike)cast)Requirement)NormalizedNamecanonicalize_name)Version)parse)InvalidWheelUnsupportedWheel)BaseDistributionBaseEntryPointInfoPathWheel)normalize_path)get_requirement)TempDirectory)parse_wheelread_wheel_metadata_file   )BadMetadataBasePathget_dist_canonical_name*parse_name_and_version_from_info_directoryc                  ^    e Zd ZdZ	 	 	 	 	 	 ddZe	 	 	 	 	 	 	 	 d	d       Zd
dZddZddZ	y)WheelDistributiona  An ``importlib.metadata.Distribution`` read from a wheel.

    Although ``importlib.metadata.PathDistribution`` accepts ``zipfile.Path``,
    its implementation is too "lazy" for pip's needs (we can't keep the ZipFile
    handle open for the entire lifetime of the distribution object).

    This implementation eagerly reads the entire metadata directory into the
    memory instead, and operates from that.
    c                     || _         || _        y N)_filesinfo_location)selffilesr%   s      Sc:\dev\xtrs\vdcb\.venv\Lib\site-packages\pip/_internal/metadata/importlib/_dists.py__init__zWheelDistribution.__init__1   s    
 *    c           	        
 t        ||      \  
}
fd|j                         D        }|D ci c]  \  }}|t        ||       }}}t        j                  |
      }	 | ||	      S c c}}w )Nc              3     K   | ]B  }|j                   d       r,|t        j                  |j                  d d      d         f D yw)/r   N)
startswithpathlibPurePosixPathsplit).0nameinfo_dirs     r(   	<genexpr>z1WheelDistribution.from_zipfile.<locals>.<genexpr>A   sK      
%(1~. 7((C);B)?@A%s   AA)r   namelistr   r0   r1   )clszfr4   location_pathsfullpathrelpathr'   r%   r5   s             @r(   from_zipfilezWheelDistribution.from_zipfile9   s     ""d+!

 &+
%*!' -b(;;%* 	 
  --hA5-((
s   A(c                    t        j                  t        |            | j                  v rt	        | j                        S t        |      r#   )r0   r1   strr$   iterFileNotFoundErrorr&   paths     r(   iterdirzWheelDistribution.iterdirM   s7      T+t{{:$$%%r*   c                
   	 | j                   t        j                  |         }	 |j	                  d      }|S # t        $ r Y y w xY w# t
        $ r2}| j                  j                  }d| d| d| d}t        |      d }~ww xY w)Nzutf-8zError decoding metadata for z: z in z file)	r$   r0   r1   KeyErrordecodeUnicodeDecodeErrorr%   parentr   )r&   filenamedatatextewheelerrors          r(   	read_textzWheelDistribution.read_textS   s    	;;w44X>?D	*;;w'D
   		 " 	*&&--E25'A3d8*ERE"5))	*s&   "8 A 	AA	B-A==Bc                    t         r#   )NotImplementedErrorrD   s     r(   locate_filezWheelDistribution.locate_file`   s
     "!r*   N)r'   z%Mapping[pathlib.PurePosixPath, bytes]r%   zpathlib.PurePosixPathreturnNone)r9   zzipfile.ZipFiler4   rA   r:   rA   rV   r!   )rE   r   rV   zIterator[pathlib.PurePosixPath])rL   rA   rV   
str | None)rE   zstr | PathLike[str]rV   zpathlib.Path)
__name__
__module____qualname____doc__r)   classmethodr?   rF   rR   rU    r*   r(   r!   r!   &   sq    +4+ -+ 
	+ )) ) 	)
 
) )&&"r*   r!   c                     e Zd Z	 	 	 	 	 	 	 	 ddZedd       Ze	 	 	 	 	 	 	 	 dd       Zedd       Zedd       Z	edd       Z
edd       Zedd       Zedd	       Zedd
       ZddZddZddZddZddZd dZd!d"dZy)#Distributionc                .    || _         || _        || _        y r#   )_dist_info_location_installed_location)r&   distr%   installed_locations       r(   r)   zDistribution.__init__g   s     
+#5 r*   c                    t        j                  |      }t        j                  j                  j                  |      } | |||j                        S r#   )r0   Path	importlibmetadatar`   atrK   )r8   	directoryr%   re   s       r(   from_directoryzDistribution.from_directoryq   sA    Y/!!..11-@4(<(<==r*   c                   t        j                  t        dd      j                        }|dz  }|j	                  |       t
        j                  j                  j                  |j                        } | ||j                  d       S )Nrj   T)kindglobally_managedMETADATA)
r0   rh   r   rE   write_bytesri   rj   r`   rk   rK   )r8   metadata_contentsrL   project_nametemp_dirmetadata_pathre   s          r(   from_metadata_file_contentsz(Distribution.from_metadata_file_contentsw   st     <<zDAFF
 !:-!!"34!!..11-2F2FG4--t44r*   c                V   	 |j                         5 }t        j                  |||j                        }d d d         | |j                  t        j                  |j                              S # 1 sw Y   :xY w# t        j
                  $ r}t        |j                  |      |d }~ww xY wr#   )

as_zipfiler!   r?   r:   zipfile
BadZipFiler   r%   r0   r1   )r8   rP   r4   r9   re   rO   s         r(   
from_wheelzDistribution.from_wheel   s    	<!!#r(55b$O $ 4++W-B-B5>>-RSS	 $#!! 	<u~~t4!;	<s-   A9 "A-A9 -A62A9 9B(B##B(c                Z    | j                   y t        | j                   j                        S r#   )rc   rA   rK   r&   s    r(   r:   zDistribution.location   s(    &4&&--..r*   c                F    | j                   y t        | j                         S r#   )rc   rA   r~   s    r(   r%   zDistribution.info_location   s"    &4&&''r*   c                X    | j                   y t        t        | j                               S r#   )rd   r   rA   r~   s    r(   rf   zDistribution.installed_location   s'    ##+c$":":;<<r*   c                ,    t        | j                        S r#   )r   rb   r~   s    r(   canonical_namezDistribution.canonical_name   s    &tzz22r*   c                    	 t        | j                        d   xs | j                  j                  }t        |      S # t        $ r t        | j                  d      w xY w)Nr   z invalid metadata entry `version`)reason)r   rb   versionparse_version	TypeErrorr   )r&   r   s     r(   r   zDistribution.version   s`    	U:4::FqI &::%%  !)) 	Udjj1STT	Us	   := !Ac                .    | j                   j                  S r#   )rb   r   r~   s    r(   raw_versionzDistribution.raw_version   s    zz!!!r*   c                N    | j                   j                  t        |            d uS r#   )rb   rR   rA   rD   s     r(   is_filezDistribution.is_file   s     zz##CI.d::r*   c              #     K   t        | j                  t        j                        sy | j                  j	                  d      j                         D ]  }|j                    y w)Nscripts)
isinstancerc   r0   rh   joinpathrF   r4   )r&   childs     r(   iter_distutils_script_namesz(Distribution.iter_distutils_script_names   sN      $--w||<((11)<DDFE** Gs   A#A%c                h    | j                   j                  t        |            }|t        |      |S r#   )rb   rR   rA   rC   )r&   rE   contents      r(   rR   zDistribution.read_text   s/    **&&s4y1?#D))r*   c                .    | j                   j                  S r#   )rb   entry_pointsr~   s    r(   iter_entry_pointszDistribution.iter_entry_points   s    zz&&&r*   c                r    t        t        j                  j                  | j                  j
                        S r#   )r
   emailmessageMessagerb   rj   r~   s    r(   _metadata_implzDistribution._metadata_impl   s%     EMM))4::+>+>??r*   c                r    | j                   j                  dg       D cg c]  }t        |       c}S c c}w )NzProvides-Extra)rj   get_allr   )r&   extras     r(   iter_provided_extrasz!Distribution.iter_provided_extras   s@     ../?D
D e$D
 	
 
s   4c              #  J  K   |D cg c]  }d|i }}| j                   j                  dg       D ]i  }t        |j                               j                  s -|s"j                  j                  ddi      r Qt        fd|D              sf k y c c}w w)Nr   zRequires-Dist c              3  T   K   | ]  }j                   j                  |       ! y wr#   )markerevaluate)r3   contextreqs     r(   r6   z1Distribution.iter_dependencies.<locals>.<genexpr>   s!     JgSZZ((1s   %()rj   r   r   stripr   r   any)r&   extrasrO   contexts
req_stringr   s        @r(   iter_dependencieszDistribution.iter_dependencies   s     DJ-KFqwlF-K--//DJ "*"2"2"45C::	

 3 3WbM B	JJJ	 E .Ls   B#BBB#B#N)re   zimportlib.metadata.Distributionr%   BasePath | Nonerf   r   rV   rW   )rl   rA   rV   r   )rs   bytesrL   rA   rt   rA   rV   r   )rP   r   r4   rA   rV   r   )rV   rX   )rV   r   )rV   r   )rV   rA   )rE   r   rV   bool)rV   zIterator[str])rE   r   rV   rA   )rV   zIterable[BaseEntryPoint])rV   zemail.message.Message)rV   zIterable[NormalizedName])r^   )r   zCollection[str]rV   zIterable[Requirement])rY   rZ   r[   r)   r]   rm   rw   r|   propertyr:   r%   rf   r   r   r   r   r   rR   r   r   r   r   r^   r*   r(   r`   r`   f   s/   6-6 '6 ,	6
 
6 > >
 5 5 5 	5
 
5 5  T T / /
 ( (
 = =
 3 3 U U " ";'@
r*   r`   )4
__future__r   email.messager   importlib.metadatari   r0   rz   collections.abcr   r   r   r   r   osr	   typingr
   "pip._vendor.packaging.requirementsr   pip._vendor.packaging.utilsr   r   pip._vendor.packaging.versionr   r   r   pip._internal.exceptionsr   r   pip._internal.metadata.baser   r   r   r   pip._internal.utils.miscr   pip._internal.utils.packagingr   pip._internal.utils.temp_dirr   pip._internal.utils.wheelr   r   _compatr   r   r   r   rj   r`   r!   r^   r*   r(   <module>r      s}    "     M M  ; I 1 @ C  4 9 6 K ="	**77 ="@# r*   