a
    QSic                     @   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   J/var/www/html/django/DPS/env/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   )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|rt|}| }W d   n1 s`0    Y  tt	
|dd d	}|D ]6\}}t||iD ] \}	}
|	|
f| vr|
||	< qq|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_pathpkginfo_pathpkg_infoZrequires_pathZrequires_filerequiresZparsed_requirementsr#   reqsr*   valuedescriptionr   r   r   pkginfo_to_metadataA   s(    
&
r;   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)r6   fieldtextitemr   r   r   pkginfo_unicode^   s    
rG   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@   rG   
splitlinesr
   lstriptextwrapdedentrB   rC   )r6   r:   Z
surrogatesZdescription_linesZdescription_dedentr   r   r   r4   l   s&    


r4   )__doc__os.pathr-   rL   r   pkginfor   r   r   r&   r;   rG   r4   r   r   r   r   <module>   s   