B
    d                 @  s   d Z ddlm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
 Zejdd Zeedd Zdd Zdd Zdd ZdddddZdddddZdd d!d"d#Zddd$d%d&d'ZdS )(z2
Tools for converting old- to new-style metadata.
    )annotationsN)Message)Parser)Iterator   )Requirementc             C  s   | o|  d S )N#)
startswith)str r   @/var/www/html/venv/lib/python3.7/site-packages/wheel/metadata.py	_nonblank   s    r   c             C  s   t jtt| S )a  
    Yield valid lines of a string or iterable.
    >>> list(yield_lines(''))
    []
    >>> list(yield_lines(['foo', 'bar']))
    ['foo', 'bar']
    >>> list(yield_lines('foo\nbar'))
    ['foo', 'bar']
    >>> list(yield_lines('\nfoo\n#bar\nbaz #comment'))
    ['foo', 'baz #comment']
    >>> list(yield_lines(['foo\nbar', 'baz', 'bing\n\n\n']))
    ['foo', 'bar', 'baz', 'bing']
    )	itertoolschainfrom_iterablemapyield_lines)iterabler   r   r   r      s    r   c             C  s   t tttj|  S )N)filterr   r   r
   strip
splitlines)textr   r   r   _(   s    r   c             c  sz   d}g }xbt | D ]V}|dr^|drR|s2|r<||fV  |dd  }g }qhtd|q|| qW ||fV  dS )ar  Split a string or iterable thereof into (section, content) pairs
    Each ``section`` is a stripped version of the section header ("[section]")
    and each ``content`` is a list of stripped lines excluding blank lines and
    comment-only lines.  If there are any such lines before the first section
    header, they're returned in a first ``section`` of ``None``.
    N[]r   zInvalid section heading)r   r	   endswithr   
ValueErrorappend)ssectioncontentliner   r   r   split_sections-   s    


r#   c             C  s   t dd|  S )zConvert an arbitrary string to a standard 'extra' name
    Any runs of non-alphanumeric characters are replaced with a single '_',
    and the result is always lowercased.
    z[^A-Za-z0-9.-]+r   )resublower)extrar   r   r   
safe_extraF   s    r(   c             C  s   t dd| S )zConvert an arbitrary string to a standard distribution name
    Any runs of non-alphanumeric/. characters are replaced with a single '-'.
    z[^A-Za-z0-9.]+-)r$   r%   )namer   r   r   	safe_nameN   s    r+   r   r
   )requirementreturnc             C  s^   t | ddrd| j S g }x | jD ]}||j|j  q"W |rVddt| d S dS dS )zFReturn the version specifier for a requirement in PEP 345/566 fashion.urlNz @ z (,) )getattrr.   	specifierr   operatorversionjoinsorted)r,   Zrequires_distspecr   r   r   requires_to_requires_distU   s    
r9   z	list[str]zIterator[str])requirementsr-   c             c  s`   xZ| D ]R}t |}t|}dtdd |jD }|rDd| d}t|j| | V  qW dS )z=Yield Requires-Dist: strings for parsed requirements strings.r/   c             s  s   | ]}t |V  qd S )N)r(   ).0er   r   r   	<genexpr>i   s    z'convert_requirements.<locals>.<genexpr>r   r   N)r   r9   r6   r7   extrasr+   r*   )r:   reqparsed_requirementr8   r>   r   r   r   convert_requirementsd   s    
rA   zdict[str, list[str]]zIterator[tuple[str, str]])extras_requirer-   c             c  s   x|   D ]\}}d}|pd}d|kr6|dd\}}t|}|rhd|fV  |r\d| d }|d| 7 }|rtd| }xt|D ]}d	|| fV  q~W q
W 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.
    r1   :r   zProvides-Extra(z) and zextra == '%s'z ; zRequires-DistN)itemssplitr(   rA   )rB   r'   depends	conditionZnew_reqr   r   r   generate_requirementsp   s    

rI   r   )egg_info_pathpkginfo_pathr-   c          
   C  s(  t |dd}t |}W dQ R X |dd |d= |d= tj| d}tj|rt |dd}| }W dQ R X t	t
|d	d
 d}xB|D ]:\}}	x0t||	iD ] \}
}|
|f| kr|||
< qW qW |d }|r$|d  }d|d  td|dd df}|| |d= |S )zN
    Convert .egg-info directory with PKG-INFO to the Metadata 2.1 format
    zutf-8)encodingNzMetadata-Versionz2.1zProvides-ExtrazRequires-Distzrequires.txtc             S  s   | d p
dS )Nr   r1   r   )xr   r   r   <lambda>       z%pkginfo_to_metadata.<locals>.<lambda>)keyDescription
r   r   )openr   parsereplace_headerospathr6   existsreadr7   r#   rI   rE   r   lstriptextwrapdedentset_payload)rJ   rK   headerspkg_infoZrequires_pathZrequires_filerequiresZparsed_requirementsr'   reqsrP   valuedescriptionZdescription_linesZdedented_descriptionr   r   r   pkginfo_to_metadata   s0    

rd   )__doc__
__future__r   	functoolsr   os.pathrV   r$   r[   email.messager   email.parserr   typingr   Zvendored.packaging.requirementsr   r   singledispatchr   registerr
   r   r#   r(   r+   r9   rA   rI   rd   r   r   r   r   <module>   s(   