
    Ce                        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	 Zej$                  d
        Zej)                  e      d        Zd Zd Zd ZddZddZ	 	 	 	 ddZddZy)z2
Tools for converting old- to new-style metadata.
    )annotationsN)Message)Parser)Iterator   )Requirementc                .    | xr | j                  d       S )N#)
startswith)strs    0/usr/lib/python3/dist-packages/wheel/metadata.py	_nonblankr      s    *s~~c***    c                \    t         j                  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)iterables    r   r   r      s      ??(([()CDDr   c                n    t        t        t        t        j                  | j                                     S N)filterr   r   r   strip
splitlines)texts    r   _r   (   s!    )SDOO,=>??r   c              #     K   d}g }t        |       D ]a  }|j                  d      r=|j                  d      r |s|r||f |dd j                         }g }Et	        d|      |j                  |       c ||f yw)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lines       r   split_sectionsr)   -   s      GGA 
!??3}}S!g!7**q***, !:DAANN4 
! 7
s   A;A=c                L    t        j                  dd|       j                         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)extras    r   
safe_extrar/   F   s!    
 66#S%06688r   c                0    t        j                  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,   )names    r   	safe_namer3   N   s     66"C..r   c                    t        | dd      rd| j                  z   S g }| j                  D ]*  }|j                  |j                  |j
                  z          , |rddj                  t        |            z   S y)zFReturn the version specifier for a requirement in PEP 345/566 fashion.urlNz @  , )getattrr5   	specifierr$   operatorversionjoinsorted)requirementrequires_distspecs      r   requires_to_requires_distrB   U   ss    {E4({&&M%% ;T]]T\\9:; SXXf]3444r   c              #     K   | D ]h  }t        |      }t        |      }dj                  t        d |j                  D                    }|rd| d}t        |j                        |z   |z    j yw)z=Yield Requires-Dist: strings for parsed requirements strings.r7   c              3  2   K   | ]  }t        |        y wr   )r/   ).0es     r   	<genexpr>z'convert_requirements.<locals>.<genexpr>i   s      R1A Rs   r   r    N)r   rB   r=   r>   extrasr3   r2   )requirementsreqparsed_requirementrA   rH   s        r   convert_requirementsrL   d   sy      A(-();<& R8J8Q8Q RRS]F*//069D@@As   A/A1c              #    K   | j                         D ]k  \  }}d}|xs d}d|v r|j                  dd      \  }}t        |      }|rd|f |rd|z   dz   }|d|z  z  }|rd|z   }t        |      D ]  }d	||z   f  m y
w)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.
    r8   :r   Provides-Extra(z) and zextra == '%s'z ; Requires-DistN)itemssplitr/   rL   )extras_requirer.   depends	conditionnew_reqs        r   generate_requirementsrX   p   s      )..0 7w	%<${{32E95!"E)))Oh6	500I	)I+G4 	7G!7Y#666	7!7s   B Bc           
         t        |d      5 }t               j                  |      }ddd       j                  dd       |d= |d= t        j
                  j                  | d      }t        j
                  j                  |      rvt        |d      5 }|j                         }ddd       t        t              d	 
      }|D ]4  \  }}	t        ||	i      D ]  \  }
}|
|f|j                         vs|||
<   ! 6 |d   }|rq|d   j                         }dj                  |d   j                         t        j                   dj                  |dd             df      }|j#                  |       |d= |S # 1 sw Y   QxY w# 1 sw Y   xY w)zN
    Convert .egg-info directory with PKG-INFO to the Metadata 2.1 format
    zutf-8)encodingNzMetadata-Versionz2.1rO   rQ   zrequires.txtc                    | d   xs dS )Nr   r8    )xs    r   <lambda>z%pkginfo_to_metadata.<locals>.<lambda>   s    QqTZUW r   )keyDescription
r   r   )openr   parsereplace_headerospathr=   existsreadr>   r)   rX   rR   r   lstriptextwrapdedentset_payload)egg_info_pathpkginfo_pathheaderspkg_inforequires_pathrequires_filerequiresparsed_requirementsr.   reqsr_   valuedescriptiondescription_linesdedented_descriptions                  r   pkginfo_to_metadatarz      s    
lW	- +8>>'*+ .6!"!GGLL?M	ww~~m$-'2 	,m$))+H	, %^H%=CWX. 	*KE43UDMB *
U<x~~'77$)HSM*	*
 =)K$]3>>@#yy "!$++-		*;AB*? @A 
 	12]#OC+ +	, 	,s   E7F7FF)r?   r   returnr   )rI   z	list[str]r{   zIterator[str])rT   zdict[str, list[str]]r{   zIterator[tuple[str, str]])rm   r   rn   r   r{   r   )__doc__
__future__r   	functoolsr   os.pathre   r+   rj   email.messager   email.parserr   typingr   vendored.packaging.requirementsr   r   singledispatchr   registerr   r   r)   r/   r3   rB   rL   rX   rz   r\   r   r   <module>r      s    #    	  !   8+ E E" c@ @29/	A7(77<%r   