a
    b3j,                     @  s2  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
mZmZ ddlmZ ddlmZ ddlmZ ddlmZ d	d
dddZejdddddZeed	dd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$Zd%dd&d'd(Zd)d*d+d,d-Z d	d	d.d/d0d1Z!dS )2z2
Tools for converting old- to new-style metadata.
    )annotationsN)	GeneratorIterableIterator)Message)Parser)Literal)Requirementstrzbool | Literal[''])r
   returnc                 C  s   | o|  d S )N#)
startswith)r
    r   l/www/wwwroot/dpstar/app/297b3aabda72fedb274352021c2dd8b5_venv/lib/python3.9/site-packages/wheel/_metadata.py	_nonblank   s    r   zIterable[str]zIterator[str])iterabler   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)r   r   r   r   r      s    r   )textr   c                 C  s   t tttj|  S N)filterr   r   r
   strip
splitlines)r   r   r   r   _*   s    r   zstr | Iterator[str]z3Generator[tuple[str | None, list[str]], None, None])sr   c                 c  sv   d}g }t | D ]V}|dr\|drP|s0|r:||fV  |dd  }g }qftd|q|| q||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[]   zInvalid section heading)r   r   endswithr   
ValueErrorappend)r   sectioncontentliner   r   r   split_sections/   s    	


r(   )extrar   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)r)   r   r   r   
safe_extraJ   s    r-   )namer   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+   )r.   r   r   r   	safe_nameR   s    r0   r	   )requirementr   c                 C  sP   | j rd| j  S g }| jD ]}||j|j  q|rHddt| S dS dS )zFReturn the version specifier for a requirement in PEP 345/566 fashion.z @  , N)url	specifierr$   operatorversionjoinsorted)r1   Zrequires_distspecr   r   r   requires_to_requires_distY   s    

r<   z	list[str])requirementsr   c                 c  s\   | D ]R}t |}t|}dtdd |jD }|rBd| d}t|j| | V  qdS )z=Yield Requires-Dist: strings for parsed requirements strings.r3   c                 s  s   | ]}t |V  qd S r   )r-   ).0er   r   r   	<genexpr>m       z'convert_requirements.<locals>.<genexpr>r   r   N)r	   r<   r9   r:   extrasr0   r.   )r=   reqparsed_requirementr;   rB   r   r   r   convert_requirementsh   s    rE   zdict[str | None, list[str]]zIterator[tuple[str, str]])extras_requirer   c                 c  s   |   D ]\}}d}|pd}d|v r4|dd\}}t|}|rjd|fV  |rZd| d }|d| d7 }|rvd	| }t|D ]}tt|| }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.
    r4   :r    Provides-Extra(z) and z
extra == ''z ; Requires-DistN)itemssplitr-   rE   r
   r	   )rF   r)   depends	conditionZnew_reqZcanonical_reqr   r   r   generate_requirementst   s     

rP   r   )egg_info_pathpkginfo_pathr   c              
   C  sH  t |dd}t |}W d   n1 s.0    Y  |dd |d= |d= tj| d}tj|rt |dd}| }W d   n1 s0    Y  t	t
|d	d
 d}|D ]6\}}	t||	iD ] \}
}|
|f| vr|||
< qq|d }|rD|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.1rH   rK   zrequires.txtc                 S  s   | d p
dS )Nr   r4   r   )xr   r   r   <lambda>   rA   z%pkginfo_to_metadata.<locals>.<lambda>)keyDescription
r   r    )openr   parsereplace_headerospathr9   existsreadr:   r(   rP   rL   r   lstriptextwrapdedentset_payload)rQ   rR   headerspkg_infoZrequires_pathZrequires_filerequiresZparsed_requirementsr)   reqsrV   valuedescriptionZdescription_linesZdedented_descriptionr   r   r   pkginfo_to_metadata   s4    *&
	
rj   )"__doc__
__future__r   	functoolsr   os.pathr\   r*   ra   collections.abcr   r   r   email.messager   email.parserr   typingr   Zpackaging.requirementsr	   r   singledispatchr   registerr
   r   r(   r-   r0   r<   rE   rP   rj   r   r   r   r   <module>   s.   