U
    ZÊ¹j  ã                   @  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mZmZ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)ÚMessage)ÚParser)Ú	GeneratorÚIterableÚIteratorÚLiteralé   )ÚRequirementÚstrzbool | Literal[''])r   Úreturnc                 C  s   | o|   d¡ S )Nú#)Ú
startswith)r   © r   úM/var/www/html/bwave/python/venv/lib/python3.8/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ú[ú]r	   éÿÿÿÿ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 )z°Convert 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_extraI   s    r-   )Únamer   c                 C  s   t  dd| ¡S )zŽConvert 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_nameQ   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_distX   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>l   s     z'convert_requirements.<locals>.<genexpr>r   r    N)r
   r<   r9   r:   Úextrasr0   r.   )r=   ÚreqÚparsed_requirementr;   rA   r   r   r   Úconvert_requirementsg   s    rD   zdict[str | None, list[str]]zIterator[tuple[str, str]])Úextras_requirer   c                 c  s¤   |   ¡ D ]–\}}d}|pd}d|k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-   rD   r   r
   )rE   r)   ÚdependsÚ	conditionZnew_reqZcanonical_reqr   r   r   Úgenerate_requirementss   s     

rO   r   )Úegg_info_pathÚpkginfo_pathr   c              
   C  s   t |dd��}tƒ  |¡}W 5 Q R X | dd¡ |d= |d= tj | d¡}tj |¡rÆt |dd��}| ¡ }W 5 Q R X t	t
|ƒdd	„ d
�}|D ]6\}}	t||	iƒD ] \}
}|
|f| ¡ kr¢|||
< q¢qŽ|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)ÚencodingzMetadata-Versionz2.1rG   rJ   zrequires.txtc                 S  s   | d p
dS )Nr   r4   r   )Úxr   r   r   Ú<lambda>¢   ó    z%pkginfo_to_metadata.<locals>.<lambda>)ÚkeyÚDescriptionÚ
r   r	   N)Úopenr   ÚparseÚreplace_headerÚosÚpathr9   ÚexistsÚreadr:   r(   rO   rK   r   ÚlstripÚtextwrapÚdedentÚset_payload)rP   rQ   Ú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   Úemail.messager   Úemail.parserr   Útypingr   r   r   r   Zvendored.packaging.requirementsr
   r   Úsingledispatchr   Úregisterr   r   r(   r-   r0   r<   rD   rO   rj   r   r   r   r   Ú<module>   s,   