o
    6‘ði,  ã                   @  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
mZmZ ddlmZ ddlmZ ddlmZ ddlmZ d3dd„Zejd4dd„ƒZe e¡d5dd„ƒZd6dd„Zd7dd„Zd8dd „Zd9d#d$„Zd:d'd(„Zd;d,d-„Z d<d1d2„Z!dS )=z2
Tools for converting old- to new-style metadata.
é    )ÚannotationsN)Ú	GeneratorÚIterableÚIterator)ÚMessage)ÚParser)ÚLiteral)ÚRequirementÚstrÚreturnúbool | Literal['']c                 C  s   | o|   d¡ S )Nú#)Ú
startswith)r
   © r   úN/root/parts/websockify/install/lib/python3.10/site-packages/wheel/_metadata.pyÚ	_nonblank   s   r   ÚiterableúIterable[str]úIterator[str]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   Útextc                 C  s   t tttj|  ¡ ƒƒS ©N)Úfilterr   r   r
   ÚstripÚ
splitlines)r   r   r   r   Ú_*   s   r   Úsústr | Iterator[str]ú3Generator[tuple[str | None, list[str]], None, None]c                 c  sv   � d}g }t | ƒD ]*}| d¡r.| d¡r)|s|r||fV  |dd…  ¡ }g }q	td|ƒ‚| |¡ 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-   Úextrac                 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_extraJ   s   r2   Únamec                 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/   r0   )r3   r   r   r   Ú	safe_nameR   s   r5   Úrequirementr	   c                 C  sL   | j rd| j  S g }| jD ]}| |j|j ¡ q|r$dd t|ƒ¡ S dS )zFReturn the version specifier for a requirement in PEP 345/566 fashion.z @ ú ú,Ú )ÚurlÚ	specifierr)   ÚoperatorÚversionÚjoinÚsorted)r6   Úrequires_distÚspecr   r   r   Úrequires_to_requires_distY   s   

rB   Úrequirementsú	list[str]c                 c  s^   � | D ])}t |ƒ}t|ƒ}d tdd„ |jD ƒƒ¡}|r"d|› d�}t|jƒ| | V  qdS )z=Yield Requires-Dist: strings for parsed requirements strings.r8   c                 s  s   � | ]}t |ƒV  qd S r   )r2   )Ú.0Úer   r   r   Ú	<genexpr>m   s   € z'convert_requirements.<locals>.<genexpr>r#   r$   N)r	   rB   r>   r?   Úextrasr5   r3   )rC   ÚreqÚparsed_requirementrA   rH   r   r   r   Úconvert_requirementsh   s   €ùrK   Úextras_requireúdict[str | None, list[str]]úIterator[tuple[str, str]]c                 c  s¦   � |   ¡ D ]K\}}d}|pd}d|v r| dd¡\}}t|ƒ}|r6d|fV  |r.d| d }|d|› d�7 }|r<d	| }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.
    r9   ú:r%   úProvides-Extraú(z) and z
extra == 'ú'z ; úRequires-DistN)ÚitemsÚsplitr2   rK   r
   r	   )rL   r.   ÚdependsÚ	conditionÚnew_reqÚcanonical_reqr   r   r   Úgenerate_requirementst   s&   €

þðrZ   Úegg_info_pathÚpkginfo_pathr   c              
   C  sF  t |dd��}tƒ  |¡}W d  ƒ n1 sw   Y  | dd¡ |d= |d= tj | d¡}tj |¡rwt |dd��}| ¡ }W d  ƒ n1 sJw   Y  t	t
|ƒd	d
„ d�}|D ]\}}	t||	iƒD ]\}
}|
|f| ¡ vru|||
< qeq[|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.1rP   rS   zrequires.txtc                 S  s   | d pdS )Nr   r9   r   )Úxr   r   r   Ú<lambda>£   s    z%pkginfo_to_metadata.<locals>.<lambda>)ÚkeyÚDescriptionÚ
r   r%   )Úopenr   ÚparseÚreplace_headerÚosÚpathr>   ÚexistsÚreadr?   r-   rZ   rT   r   ÚlstripÚtextwrapÚdedentÚset_payload)r[   r\   ÚheadersÚpkg_infoÚrequires_pathÚrequires_fileÚrequiresÚparsed_requirementsr.   Úreqsr`   ÚvalueÚdescriptionÚdescription_linesÚdedented_descriptionr   r   r   Úpkginfo_to_metadata“   s<   ÿ
ÿ€þ
ýý
	ry   )r
   r
   r   r   )r   r   r   r   )r   r
   r   r   )r    r!   r   r"   )r.   r
   r   r
   )r3   r
   r   r
   )r6   r	   r   r
   )rC   rD   r   r   )rL   rM   r   rN   )r[   r
   r\   r
   r   r   )"Ú__doc__Ú
__future__r   Ú	functoolsr   Úos.pathrf   r/   rk   Úcollections.abcr   r   r   Úemail.messager   Úemail.parserr   Útypingr   Úpackaging.requirementsr	   r   Úsingledispatchr   Úregisterr
   r   r-   r2   r5   rB   rK   rZ   ry   r   r   r   r   Ú<module>   s0    






