a
    ´i>I  ã                   @   s’  d dl Z d dlZd dlZd dlZd dlZd dlZd dlZd dlZd dlZd dl	Z	d dl
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 d dlmZ g d¢ZG dd	„ d	eƒZG d
d„ de dd¡ƒZG dd„ dejƒZG dd„ dƒZG dd„ dƒZG dd„ deƒZ G dd„ dƒZ!G dd„ dƒZ"G dd„ de ƒZ#G dd„ deƒZ$dd„ Z%d d!„ Z&d"d#„ Z'd$d%„ Z(d&d'„ Z)d(d)„ Z*d*d+„ Z+dS ),é    N)ÚConfigParser)Úsuppress)Úimport_module)ÚMetaPathFinder)Ústarmap)
ÚDistributionÚDistributionFinderÚPackageNotFoundErrorÚdistributionÚdistributionsÚentry_pointsÚfilesÚmetadataÚrequiresÚversionc                   @   s   e Zd ZdS )r	   N)Ú__name__Ú
__module__Ú__qualname__© r   r   ú*/usr/lib64/python3.9/importlib/metadata.pyr	   %   s   r	   c                   @   sj   e Zd Ze 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dd„ Zdd„ ZdS )Ú
EntryPointzH(?P<module>[\w.]+)\s*(:\s*(?P<attr>[\w.]+)\s*)?((?P<extras>\[.*\])\s*)?$c                 C   sD   | j  | j¡}t| d¡ƒ}td | d¡p,d d¡ƒ}t t	||¡S )NÚmoduleÚattrÚ Ú.)
ÚpatternÚmatchÚvaluer   ÚgroupÚfilterÚsplitÚ	functoolsÚreduceÚgetattr)Úselfr   r   Úattrsr   r   r   ÚloadP   s    zEntryPoint.loadc                 C   s   | j  | j¡}| d¡S )Nr   ©r   r   r   r   ©r$   r   r   r   r   r   Z   s    zEntryPoint.modulec                 C   s   | j  | j¡}| d¡S )Nr   r'   r(   r   r   r   r   _   s    zEntryPoint.attrc                 C   s$   | j  | j¡}t d| d¡p d¡S )Nz\w+Úextrasr   )r   r   r   ÚreÚfindallr   r(   r   r   r   r)   d   s    zEntryPoint.extrasc                    s   ‡ ‡fdd„ˆ  ¡ D ƒS )Nc                    s,   g | ]$}ˆ  |¡D ]\}}ˆ |||ƒ‘qqS r   ©Úitems)Ú.0r   Únamer   ©ÚclsÚconfigr   r   Ú
<listcomp>k   s   þz+EntryPoint._from_config.<locals>.<listcomp>)Úsectionsr0   r   r0   r   Ú_from_configi   s    þzEntryPoint._from_configc                 C   sL   t dd�}t|_z| |¡ W n" ty@   | t |¡¡ Y n0 t 	|¡S )Nú=)Z
delimiters)
r   ÚstrZoptionxformZread_stringÚAttributeErrorZreadfpÚioÚStringIOr   r5   )r1   Útextr2   r   r   r   Ú
_from_textq   s    
zEntryPoint._from_textc                 C   s   t | j| fƒS ©N)Úiterr/   ©r$   r   r   r   Ú__iter__}   s    zEntryPoint.__iter__c                 C   s   | j | j| j| jffS r=   )Ú	__class__r/   r   r   r?   r   r   r   Ú
__reduce__ƒ   s    þzEntryPoint.__reduce__N)r   r   r   r*   Úcompiler   r&   Úpropertyr   r   r)   Úclassmethodr5   r<   r@   rB   r   r   r   r   r   )   s    ÿ





r   ZEntryPointBasezname value groupc                   @   s&   e Zd Zd	dd„Zdd„ Zdd„ ZdS )
ÚPackagePathúutf-8c                 C   s<   |   ¡ j|d��}| ¡ W  d   ƒ S 1 s.0    Y  d S )N©Úencoding©ÚlocateÚopenÚread)r$   rI   Ústreamr   r   r   Ú	read_text�   s    zPackagePath.read_textc                 C   s:   |   ¡  d¡�}| ¡ W  d   ƒ S 1 s,0    Y  d S )NÚrbrJ   )r$   rN   r   r   r   Úread_binary‘   s    zPackagePath.read_binaryc                 C   s   | j  | ¡S r=   )ÚdistÚlocate_filer?   r   r   r   rK   •   s    zPackagePath.locateN)rG   )r   r   r   rO   rQ   rK   r   r   r   r   rF   Š   s   
rF   c                   @   s   e Zd Zdd„ Zdd„ ZdS )ÚFileHashc                 C   s   |  d¡\| _}| _d S )Nr6   )Ú	partitionÚmoder   )r$   ÚspecÚ_r   r   r   Ú__init__›   s    zFileHash.__init__c                 C   s   d  | j| j¡S )Nz<FileHash mode: {} value: {}>)ÚformatrV   r   r?   r   r   r   Ú__repr__ž   s    zFileHash.__repr__N)r   r   r   rY   r[   r   r   r   r   rT   š   s   rT   c                   @   sæ   e Zd Zejdd„ ƒZejdd„ ƒZedd„ ƒZedd„ ƒZ	e
d	d
„ ƒZe
dd„ ƒZed)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edd„ ƒZdd„ Zd d!„ Zed"d#„ ƒZe
d$d%„ ƒZe
d&d'„ ƒZd(S )*r   c                 C   s   d S r=   r   ©r$   Úfilenamer   r   r   rO   ¥   s    zDistribution.read_textc                 C   s   d S r=   r   ©r$   Úpathr   r   r   rS   ­   s    zDistribution.locate_filec                 C   sH   |   ¡ D ]2}|tj|d�ƒ}tt|ƒd ƒ}|d ur|  S qt|ƒ‚d S )N©r/   )Ú_discover_resolversr   ÚContextÚnextr>   r	   )r1   r/   ÚresolverZdistsrR   r   r   r   Ú	from_name´   s    

zDistribution.from_namec                    sN   |  dd ¡‰ ˆ r|rtdƒ‚ˆ p.tjf i |¤Ž‰ tj ‡ fdd„|  ¡ D ƒ¡S )NÚcontextz cannot accept context and kwargsc                 3   s   | ]}|ˆ ƒV  qd S r=   r   )r.   rd   ©rf   r   r   Ú	<genexpr>Ô   s   ÿz(Distribution.discover.<locals>.<genexpr>)ÚpopÚ
ValueErrorr   rb   Ú	itertoolsÚchainÚfrom_iterablera   )r1   Úkwargsr   rg   r   ÚdiscoverÆ   s    
þzDistribution.discoverc                 C   s   t t | ¡ƒS r=   )ÚPathDistributionÚpathlibÚPath)r_   r   r   r   ÚatÙ   s    zDistribution.atc                  C   s   dd„ t jD ƒ} td | ƒS )Nc                 s   s   | ]}t |d dƒV  qdS )Úfind_distributionsN)r#   )r.   Úfinderr   r   r   rh   å   s   ÿz3Distribution._discover_resolvers.<locals>.<genexpr>)ÚsysÚ	meta_pathr   )Zdeclaredr   r   r   ra   â   s    þz Distribution._discover_resolversr   c                 C   s@   ddl m}m} | |¡}tj|j||d�}tt | 	|¡¡ƒS )Nr   )ÚbuildÚmeta)Z
source_dirÚsystem)
Zpep517rx   ry   Zcompat_systemr!   Úpartialrp   Úzipfilerr   Zbuild_as_zip)r1   Úrootrx   ry   rz   Zbuilderr   r   r   Ú_localë   s    
ýzDistribution._localc                 C   s(   |   d¡p|   d¡p|   d¡}t |¡S )NZMETADATAzPKG-INFOr   )rO   ÚemailZmessage_from_string©r$   r;   r   r   r   r   ö   s    
ÿúzDistribution.metadatac                 C   s
   | j d S )NZVersion)r   r?   r   r   r   r     s    zDistribution.versionc                 C   s   t  |  d¡¡S )Nzentry_points.txt)r   r<   rO   r?   r   r   r   r     s    zDistribution.entry_pointsc                    s6   ˆ   ¡ pˆ  ¡ }d‡ fdd„	}|o4tt|t |¡ƒƒS )Nc                    s6   t | ƒ}|rt|ƒnd |_|r&t|ƒnd |_ˆ |_|S r=   )rF   rT   ÚhashÚintÚsizerR   )r/   r�   Zsize_strÚresultr?   r   r   Ú	make_file  s
    z%Distribution.files.<locals>.make_file)NN)Ú_read_files_distinfoÚ_read_files_egginfoÚlistr   ÚcsvÚreader)r$   Z
file_linesr…   r   r?   r   r     s    zDistribution.filesc                 C   s   |   d¡}|o| ¡ S )NZRECORD)rO   Ú
splitlinesr€   r   r   r   r†   &  s    
z!Distribution._read_files_distinfoc                 C   s   |   d¡}|otdj| ¡ ƒS )NzSOURCES.txtz"{}")rO   ÚmaprZ   r‹   r€   r   r   r   r‡   -  s    
z Distribution._read_files_egginfoc                 C   s   |   ¡ p|  ¡ }|ot|ƒS r=   )Ú_read_dist_info_reqsÚ_read_egg_info_reqsrˆ   )r$   Zreqsr   r   r   r   5  s    zDistribution.requiresc                 C   s   | j  d¡S )NzRequires-Dist)r   Zget_allr?   r   r   r   r�   ;  s    z!Distribution._read_dist_info_reqsc                 C   s    |   d¡}|d u rd S |  |¡S )Nzrequires.txt)rO   Ú_deps_from_requires_text)r$   Úsourcer   r   r   rŽ   >  s    
z Distribution._read_egg_info_reqsc                 C   s4   |   | ¡ ¡}dd„ t |t d¡¡D ƒ}|  |¡S )Nc                 S   s&   i | ]\}}|t tt d ¡|ƒƒ“qS )Úline)rˆ   rŒ   ÚoperatorÚ
itemgetter)r.   ÚsectionÚresultsr   r   r   Ú
<dictcomp>E  s   ÿz9Distribution._deps_from_requires_text.<locals>.<dictcomp>r”   )Ú_read_sectionsr‹   rk   Úgroupbyr’   r“   Ú%_convert_egg_info_reqs_to_simple_reqs)r1   r�   Zsection_pairsr4   r   r   r   r�   B  s
    ýz%Distribution._deps_from_requires_textc                 c   s<   d }t d | ƒD ](}t d|¡}|r.| d¡}qtƒ V  qd S )Nz	\[(.*)\]$é   )r   r*   r   r   Úlocals)Úlinesr”   r‘   Zsection_matchr   r   r   r—   L  s    
zDistribution._read_sectionsc                 #   sV   dd„ ‰ ‡ fdd„}dd„ }|   ¡ D ],\}}|D ]}||ƒ}|| ||ƒ V  q0q$d S )Nc                 S   s   | odj | d�S )Nzextra == "{name}"r`   )rZ   r`   r   r   r   Úmake_conditiona  s    zJDistribution._convert_egg_info_reqs_to_simple_reqs.<locals>.make_conditionc                    sX   | pd} |   d¡\}}}|r,|r,d|› d�}ttd |ˆ |ƒgƒƒ}|rTdd |¡ S dS )Nr   ú:ú(ú)z; z and )rU   rˆ   r   Újoin)r”   ÚextraÚsepZmarkersZ
conditions©r�   r   r   Úquoted_markerd  s    zIDistribution._convert_egg_info_reqs_to_simple_reqs.<locals>.quoted_markerc                 S   s   dd| v  S )Nú ú@r   )Zreqr   r   r   Úurl_req_spacel  s    zIDistribution._convert_egg_info_reqs_to_simple_reqs.<locals>.url_req_spacer,   )r4   r¥   r¨   r”   ZdepsZdepÚspacer   r¤   r   r™   V  s    z2Distribution._convert_egg_info_reqs_to_simple_reqsN)r   )r   r   r   ÚabcÚabstractmethodrO   rS   rE   re   ro   Ústaticmethodrs   ra   r~   rD   r   r   r   r   r†   r‡   r   r�   rŽ   r�   r—   r™   r   r   r   r   r   ¢   sD   












	
	r   c                   @   s.   e Zd ZG dd„ dƒZejeƒ fdd„ƒZdS )r   c                   @   s$   e Zd ZdZdd„ Zedd„ ƒZdS )zDistributionFinder.ContextNc                 K   s   t | ƒ |¡ d S r=   )ÚvarsÚupdate)r$   rn   r   r   r   rY   ‘  s    z#DistributionFinder.Context.__init__c                 C   s   t | ƒ dtj¡S )Nr_   )r­   Úgetrv   r_   r?   r   r   r   r_   ”  s    zDistributionFinder.Context.path)r   r   r   r/   rY   rD   r_   r   r   r   r   rb     s   rb   c                 C   s   d S r=   r   )r$   rf   r   r   r   rt   ž  s    z%DistributionFinder.find_distributionsN)r   r   r   rb   rª   r«   rt   r   r   r   r   r   z  s   r   c                   @   s<   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	d
„ Zdd„ ZdS )ÚFastPathc                 C   s   || _ tj | j ¡ ¡ | _d S r=   )r}   Úosr_   ÚbasenameÚlowerÚbase)r$   r}   r   r   r   rY   ¯  s    zFastPath.__init__c                 C   s   t  | j|¡S r=   )rq   rr   r}   )r$   Úchildr   r   r   Újoinpath³  s    zFastPath.joinpathc                 C   sl   t tƒ�  t | jpd¡W  d   ƒ S 1 s.0    Y  t tƒ� |  ¡ W  d   ƒ S 1 s^0    Y  g S )Nr   )r   Ú	Exceptionr±   Úlistdirr}   Úzip_childrenr?   r   r   r   Úchildren¶  s
    
.
&zFastPath.childrenc                 C   s2   t  | j¡}|j ¡ }|j| _t dd„ |D ƒ¡S )Nc                 s   s    | ]}|  tjd ¡d V  qdS )rš   r   N)r    Ú	posixpathr£   )r.   rµ   r   r   r   rh   Â  s   ÿz(FastPath.zip_children.<locals>.<genexpr>)r|   rr   r}   Znamelistr¶   ÚdictÚfromkeys)r$   Zzip_pathÚnamesr   r   r   r¹   ½  s    

þzFastPath.zip_childrenc                 C   s&   | j }||jkp$| |j¡o$| d¡S )Nú.egg)r´   Úversionless_egg_nameÚ
startswithÚprefixÚendswith)r$   Úsearchr´   r   r   r   Úis_eggÇ  s
    
ýzFastPath.is_eggc                 c   sZ   |   ¡ D ]L}| ¡ }||jv sH| |j¡r6| |j¡sH|  |¡r|dkr|  |¡V  qd S )Nzegg-info)	rº   r³   Úexact_matchesrÁ   rÂ   rÃ   ÚsuffixesrÅ   r¶   )r$   r/   rµ   Zn_lowr   r   r   rÄ   Î  s    

ÿ
þüüzFastPath.searchN)	r   r   r   rY   r¶   rº   r¹   rÅ   rÄ   r   r   r   r   r°   ©  s   
r°   c                   @   s2   e Zd ZdZdZdZdgdd… ZdZdd„ ZdS )ÚPreparedr   )z
.dist-infoz	.egg-infoNr   c                    sV   |ˆ _ |d u rd S | ¡  dd¡ˆ _ˆ jd ˆ _‡ fdd„ˆ jD ƒˆ _ˆ jd ˆ _d S )Nú-rX   c                    s   g | ]}ˆ j | ‘qS r   )Ú
normalized)r.   Úsuffixr?   r   r   r3   é  s   z%Prepared.__init__.<locals>.<listcomp>r¿   )r/   r³   ÚreplacerÊ   rÂ   rÇ   rÆ   rÀ   )r$   r/   r   r?   r   rY   ã  s    
ÿzPrepared.__init__)	r   r   r   rÊ   rÂ   rÇ   rÆ   rÀ   rY   r   r   r   r   rÈ   Ù  s   rÈ   c                   @   s,   e Zd Zee ¡ fdd„ƒZedd„ ƒZdS )ÚMetadataPathFinderc                 C   s   |   |j|j¡}tt|ƒS r=   )Ú_search_pathsr/   r_   rŒ   rp   )r1   rf   Úfoundr   r   r   rt   ï  s    
z%MetadataPathFinder.find_distributionsc                    s    t j ‡ fdd„tt|ƒD ƒ¡S )Nc                 3   s   | ]}|  tˆ ƒ¡V  qd S r=   )rÄ   rÈ   )r.   r_   r`   r   r   rh   ÿ  s   ÿz3MetadataPathFinder._search_paths.<locals>.<genexpr>)rk   rl   rm   rŒ   r°   )r1   r/   Úpathsr   r`   r   rÎ   ü  s    þz MetadataPathFinder._search_pathsN)r   r   r   rE   r   rb   rt   rÎ   r   r   r   r   rÍ   î  s   rÍ   c                   @   s.   e Zd Zdd„ Zdd„ Zejje_dd„ ZdS )rp   c                 C   s
   || _ d S r=   )Ú_pathr^   r   r   r   rY     s    zPathDistribution.__init__c                 C   sH   t tttttƒ�$ | j |¡jdd�W  d   ƒ S 1 s:0    Y  d S )NrG   rH   )	r   ÚFileNotFoundErrorÚIsADirectoryErrorÚKeyErrorÚNotADirectoryErrorÚPermissionErrorrÑ   r¶   rO   r\   r   r   r   rO     s    ÿzPathDistribution.read_textc                 C   s   | j j| S r=   )rÑ   Úparentr^   r   r   r   rS     s    zPathDistribution.locate_fileN)r   r   r   rY   rO   r   Ú__doc__rS   r   r   r   r   rp     s   
rp   c                 C   s
   t  | ¡S r=   )r   re   ©Zdistribution_namer   r   r   r
     s    r
   c                  K   s   t jf i | ¤ŽS r=   )r   ro   )rn   r   r   r   r   !  s    r   c                 C   s   t  | ¡jS r=   )r   re   r   rÙ   r   r   r   r   )  s    r   c                 C   s
   t | ƒjS r=   )r
   r   rÙ   r   r   r   r   2  s    r   c                  C   sH   t j dd„ tƒ D ƒ¡} t d¡}t| |d�}t  ||¡}dd„ |D ƒS )Nc                 s   s   | ]}|j V  qd S r=   )r   )r.   rR   r   r   r   rh   A  s   zentry_points.<locals>.<genexpr>r   )Úkeyc                 S   s   i | ]\}}|t |ƒ“qS r   )Útuple)r.   r   Úepsr   r   r   r–   F  s   ÿz entry_points.<locals>.<dictcomp>)rk   rl   rm   r   r’   Ú
attrgetterÚsortedr˜   )rÜ   Zby_groupZorderedZgroupedr   r   r   r   <  s    ÿ
þr   c                 C   s
   t | ƒjS r=   )r
   r   rÙ   r   r   r   r   L  s    r   c                 C   s
   t | ƒjS r=   )r
   r   rÙ   r   r   r   r   U  s    r   ),r9   r±   r*   rª   r‰   rv   r   rq   r|   r’   r!   rk   r»   ÚcollectionsÚconfigparserr   Ú
contextlibr   Ú	importlibr   Úimportlib.abcr   r   Ú__all__ÚModuleNotFoundErrorr	   Ú
namedtupler   ÚPurePosixPathrF   rT   r   r   r°   rÈ   rÍ   rp   r
   r   r   r   r   r   r   r   r   r   r   Ú<module>   sN   

ÿa Y/0		
	