a
    xÏOcø  ã                   @   s\   d Z ddlZddlZddlZddlmZ dd„ Zdd„ Zd	d
„ Z	dd„ Z
dd„ Zdd„ ZdS )z2
Tools for converting old- to new-style metadata.
é    Né   )Úread_pkg_infoc                 C   sR   t | ddƒrd| j S g }| jD ]\}}| || ¡ q |s@dS dd t|ƒ¡ S )zFReturn the version specifier for a requirement in PEP 345/566 fashion.ÚurlNz @ Ú z (%s)ú,)Úgetattrr   ÚspecsÚappendÚjoinÚsorted)ÚrequirementZrequires_distÚopÚver© r   úE/var/www/html/gsl.tools/lib/python3.9/site-packages/wheel/metadata.pyÚrequires_to_requires_dist   s    
r   c                 c   sN   | D ]D}t j |¡}t|ƒ}d t|jƒ¡}|r8d| }|j| | V  qdS )z=Yield Requires-Dist: strings for parsed requirements strings.r   z[%s]N)Úpkg_resourcesÚRequirementÚparser   r
   r   ÚextrasÚproject_name)ÚrequirementsÚreqZparsed_requirementÚspecr   r   r   r   Úconvert_requirements   s    r   c                 c   s–   |   ¡ D ]ˆ\}}d}|pd}d|v r4| dd¡\}}t |¡}|rhd|fV  |r\d| d }|d| 7 }|rtd| }t|ƒD ]}d	|| fV  q|qd
S )a,  
    Convert requirements from a setup()-style dictionary to ('Requires-Dist', 'requirement')
    and ('Provides-Extra', 'extra') tuples.

    extras_require is a dictionary of {extra: [requirements]} as passed to setup(),
    using the empty extra {'': [requirements]} to hold install_requires.
    r   ú:r   úProvides-Extraú(z) and zextra == '%s'z ; úRequires-DistN)ÚitemsÚsplitr   Ú
safe_extrar   )Zextras_requireÚextraÚdependsÚ	conditionZnew_reqr   r   r   Úgenerate_requirements%   s    

r%   c                 C   sà   t |ƒ}| dd¡ |d= |d= tj | d¡}tj |¡r¼t|ƒ�}| ¡ }W d  ƒ n1 s`0    Y  tt	 
|¡dd„ d	�}|D ]6\}}t||iƒD ] \}	}
|	|
f| ¡ vr˜|
||	< q˜q„|d
 }|rÜ| t|ƒ¡ |d
= |S )zN
    Convert .egg-info directory with PKG-INFO to the Metadata 2.1 format
    zMetadata-Versionz2.1r   r   zrequires.txtNc                 S   s   | d p
dS )Nr   r   r   )Úxr   r   r   Ú<lambda>P   ó    z%pkginfo_to_metadata.<locals>.<lambda>)ÚkeyÚDescription)r   Úreplace_headerÚosÚpathr
   ÚexistsÚopenÚreadr   r   Úsplit_sectionsr%   r   Úset_payloadÚdedent_description)Zegg_info_pathZpkginfo_pathÚpkg_infoZrequires_pathZrequires_fileÚrequiresZparsed_requirementsr"   Úreqsr)   ÚvalueÚdescriptionr   r   r   Úpkginfo_to_metadataA   s(    
&
ÿr9   c                 C   sV   | | }|  ¡ }t|tƒsR|  ¡ D ].}|d   ¡ |kr"|d  dd¡ d¡} qRq"|S )z<Hack to coax Unicode out of an email Message() - Python 3.3+r   r   ÚasciiÚsurrogateescapezutf-8)ÚlowerÚ
isinstanceÚstrÚ	raw_itemsÚencodeÚdecode)r4   ÚfieldÚtextÚitemr   r   r   Úpkginfo_unicode^   s    
ÿrE   c              
   C   sr   | d }d}t |tƒs$d}t| dƒ}| ¡ }d |d  ¡ t d |dd… ¡¡df¡}|rn| d¡ 	d	d
¡}|S )z@
    Dedent and convert pkg_info['Description'] to Unicode.
    r*   FTÚ
r   r   NÚutf8r:   r;   )
r=   r>   rE   Ú
splitlinesr
   ÚlstripÚtextwrapÚdedentr@   rA   )r4   r8   Z
surrogatesZdescription_linesZdescription_dedentr   r   r   r3   l   s&    


þýÿþr3   )Ú__doc__Úos.pathr,   rJ   r   Zpkginfor   r   r   r%   r9   rE   r3   r   r   r   r   Ú<module>   s   