U
    +5øiŸB  ã                	   @  s   U d dl m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	m
Z
mZmZmZ ddlmZmZmZmZmZ ddlmZ ddlmZ ddlmZmZ dd	lmZ d
ddddddgZddœdd„Zeeeeee f ge f Z!e	d Z"ddhZ#ddddhZ$G dd„ de%ƒZ&G dd„ de%ƒZ'G dd„ de%ƒZ(G dd
„ d
eƒZ)d d d!œd"d#„Z*d$d$d%œd&d'„Z+dNd)d*d+d,œd-d.„Z,d/d0„ d1d0„ d2d0„ ej-ej-ej.ej-d3d0„ d4œZ/d5e0d6< d+d7d8d+d9d:œd;d<„Z1d+d8d+d=d>œd?d@„Z2d$dAd9dBœdCdD„Z3dEd+dFœdGdH„Z4d
dœdId„Z5G dJd„ dƒZ6dAdAdKœdLdM„Z7dS )Oé    )ÚannotationsN)ÚAbstractSetÚCallableÚLiteralÚMappingÚ	TypedDictÚUnionÚcasté   )Ú
MarkerAtomÚ
MarkerListÚOpÚValueÚVariable)Úparse_marker)ÚParserSyntaxError)ÚInvalidSpecifierÚ	Specifier©Úcanonicalize_nameÚEnvironmentÚEvaluateContextÚInvalidMarkerÚMarkerÚUndefinedComparisonÚUndefinedEnvironmentNameÚdefault_environmentz	list[str]©Úreturnc                   C  s   t S ©N)Ú__all__© r!   r!   ú5/tmp/pip-unpacked-wheel-xj899fla/packaging/markers.pyÚ__dir__   s    r#   )ÚmetadataÚ	lock_fileÚrequirementÚextrasÚdependency_groupsÚimplementation_versionÚplatform_releaseÚpython_full_versionÚpython_versionc                   @  s   e Zd ZdZdS )r   zëRaised when attempting to create a :class:`Marker` from invalid input.

    This error indicates that the given marker string does not conform to the
    :ref:`specification of dependency specifiers <pypug:dependency-specifiers>`.
    N©Ú__name__Ú
__module__Ú__qualname__Ú__doc__r!   r!   r!   r"   r   6   s   c                   @  s   e Zd ZdZdS )r   zçRaised when evaluating an unsupported marker comparison.

    This can happen when marker values are compared as versions but do not
    conform to the :ref:`specification of version specifiers
    <pypug:version-specifiers>`.
    Nr-   r!   r!   r!   r"   r   >   s   c                   @  s   e Zd ZdZdS )r   zJRaised when evaluating a marker that references a missing environment key.Nr-   r!   r!   r!   r"   r   G   s   c                   @  sj   e Zd ZU dZded< ded< ded< ded< ded< ded< ded	< ded
< ded< ded< ded< dS )r   z„
    A dictionary that represents a Python environment as captured by
    :func:`default_environment`. All fields are required.
    ÚstrÚimplementation_namer)   Úos_nameÚplatform_machiner*   Úplatform_systemÚplatform_versionr+   Úplatform_python_implementationr,   Úsys_platformN)r.   r/   r0   r1   Ú__annotations__r!   r!   r!   r"   r   K   s   
zMarkerList | MarkerAtom | str)Úresultr   c                 C  sp   t | tƒs| S | \}}}t |tƒr@|jdkr@t|jƒ}t|ƒ}n&t |tƒrf|jdkrft|jƒ}t|ƒ}|||fS )NÚextra)Ú
isinstanceÚtupler   Úvaluer   r   )r;   ÚlhsÚopÚrhsZnormalized_extrar!   r!   r"   Ú_normalize_extras˜   s    




rC   r   )Úresultsr   c                 C  s   dd„ | D ƒS )z!
    Normalize extra values.
    c                 S  s   g | ]}t |ƒ‘qS r!   )rC   )Ú.0Úrr!   r!   r"   Ú
<listcomp>­   s     z+_normalize_extra_values.<locals>.<listcomp>r!   )rD   r!   r!   r"   Ú_normalize_extra_values¨   s    rH   Tzlist[str] | MarkerAtom | strzbool | Noner2   )ÚmarkerÚfirstr   c                 C  s¨   t | tttfƒst‚t | tƒrHt| ƒdkrHt | d ttfƒrHt| d ƒS t | tƒr‚dd„ | D ƒ}|rnd |¡S dd |¡ d S n"t | tƒr d dd	„ | D ƒ¡S | S d S )
Nr
   r   c                 s  s   | ]}t |d d�V  qdS )F)rJ   N)Ú_format_marker©rE   Úmr!   r!   r"   Ú	<genexpr>Á   s     z!_format_marker.<locals>.<genexpr>ú ú(ú)c                 S  s   g | ]}|  ¡ ‘qS r!   )Ú	serializerL   r!   r!   r"   rG   Ç   s     z"_format_marker.<locals>.<listcomp>)r=   Úlistr>   r2   ÚAssertionErrorÚlenrK   Újoin)rI   rJ   Úinnerr!   r!   r"   rK   °   s     ÿ
þý


rK   c                 C  s   | |kS r   r!   ©r@   rB   r!   r!   r"   Ú<lambda>Í   ó    rY   c                 C  s   | |kS r   r!   rX   r!   r!   r"   rY   Î   rZ   c                 C  s   dS ©NFr!   ©Z_lhsZ_rhsr!   r!   r"   rY   Ï   rZ   c                 C  s   dS r[   r!   r\   r!   r!   r"   rY   Ô   rZ   )Úinznot inú<z<=z==z!=z>=ú>zdict[str, Operator]Ú
_operatorsr   zstr | AbstractSet[str]Úbool)r@   rA   rB   Úkeyr   c                C  s€   |  ¡ }|tkrHzt|› |› �ƒ}W n tk
r8   Y nX |j| dd�S t |¡}|d krvtd|›d| ›d|›d�ƒ‚|| |ƒS )NT)Úprereleasesz
Undefined z on z and Ú.)rR   ÚMARKERS_REQUIRING_VERSIONr   r   Úcontainsr`   Úgetr   )r@   rA   rB   rb   Zop_strÚspecÚoperr!   r!   r"   Ú_eval_opØ   s    
rj   z"tuple[str, str | AbstractSet[str]])r@   rB   rb   r   c                 C  sb   |dkr"t |tƒstdƒ‚| |fS |tkrZt |tƒrDt| ƒt|ƒfS t| ƒdd„ |D ƒfS | |fS )Nr<   zextra value must be a stringc                 S  s   h | ]}t |ƒ’qS r!   r   )rE   Úvr!   r!   r"   Ú	<setcomp>ø   s     z_normalize.<locals>.<setcomp>)r=   r2   rT   ÚMARKERS_ALLOWING_SETr   )r@   rB   rb   r!   r!   r"   Ú
_normalizeé   s    
rn   ú!dict[str, str | AbstractSet[str]])ÚmarkersÚenvironmentr   c           
   	   C  sö   g g}| D ]Ø}t |tƒr.|d  t||ƒ¡ q
t |tƒr¶|\}}}t |tƒrb|j}|| }|j}	n|j}|j}|| }	t |tƒsˆtdƒ‚t	||	|d�\}}	|d  t
|||	|d�¡ q
|dkrÊ| g ¡ q
|dkrÔq
td|›�ƒ‚q
tdd„ |D ƒƒS )	Néÿÿÿÿzlhs must be a string)rb   ÚorÚandzUnexpected marker c                 s  s   | ]}t |ƒV  qd S r   )Úall)rE   Úitemr!   r!   r"   rN     s     z$_evaluate_markers.<locals>.<genexpr>)r=   rS   ÚappendÚ_evaluate_markersr>   r   r?   r2   rT   rn   rj   Ú	TypeErrorÚany)
rp   rq   ÚgroupsrI   r@   rA   rB   Zenvironment_keyÚ	lhs_valueÚ	rhs_valuer!   r!   r"   rx   þ   s,    



rx   zsys._version_info)Úinfor   c                 C  sB   | j › d| j› d| j› �}| j}|dkr>||d t| jƒ 7 }|S )Nrd   Úfinalr   )ÚmajorÚminorÚmicroÚreleaselevelr2   Úserial)r~   ÚversionÚkindr!   r!   r"   Ú_format_full_version  s
    r‡   c                  C  s^   t tjjƒ} tjj}|| tjt ¡ t ¡ t 	¡ t ¡ t 
¡ t ¡ d t ¡ dd… ¡tjdœS )z�Return the default marker environment for the current Python process.

    This is the base environment used by :meth:`Marker.evaluate`.
    rd   Né   )r3   r)   r4   r5   r*   r6   r7   r+   r8   r,   r9   )r‡   ÚsysÚimplementationr…   ÚnameÚosÚplatformÚmachineÚreleaseÚsystemr,   Úpython_implementationrV   Úpython_version_tuple)Úiverr3   r!   r!   r"   r   '  s    õc                   @  sÄ   e Zd ZdZdZdddœdd„Zedd d	œd
d„ƒZddœdd„Zddœdd„Z	ddœdd„Z
dddœdd„Z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&œd'd(„Zd"S )*r   aê  Represents a parsed dependency marker expression.

    Marker expressions are parsed according to the
    :ref:`specification of dependency specifiers <pypug:dependency-specifiers>`.

    :param marker: The string representation of a marker expression.
    :raises InvalidMarker: If ``marker`` cannot be parsed.

    Instances are safe to serialize with :mod:`pickle`. They use a stable
    format so the same pickle can be loaded in future packaging releases.

    .. versionchanged:: 26.2

        Added a stable pickle format. Pickles created with packaging 26.2+ can
        be unpickled with future releases.  Backward compatibility with pickles
        from packaging < 26.2 is supported but may be removed in a future
        release.
    )Ú_markersr2   ÚNone)rI   r   c              
   C  sN   g | _ ztt|ƒƒ| _ W n0 tk
rH } ztt|ƒƒ|‚W 5 d }~X Y nX d S r   )r”   rH   Ú_parse_markerr   r   r2   )ÚselfrI   Úer!   r!   r"   Ú__init__S  s
    zMarker.__init__r   )rp   r   c                 C  s   |   | ¡}||_|S )z’Create a Marker instance from a pre-parsed marker tree.

        This avoids re-parsing serialised marker strings when combining markers.
        )Ú__new__r”   )Úclsrp   Únewr!   r!   r"   Ú_from_markersq  s    
zMarker._from_markersr   c                 C  s
   t | jƒS r   )rK   r”   ©r—   r!   r!   r"   Ú__str__{  s    zMarker.__str__c                 C  s   d| j j› dt| ƒ›d�S )Nr^   rP   z)>)Ú	__class__r.   r2   rž   r!   r!   r"   Ú__repr__~  s    zMarker.__repr__Úintc                 C  s   t t| ƒƒS r   )Úhashr2   rž   r!   r!   r"   Ú__hash__�  s    zMarker.__hash__Úobjectra   )Úotherr   c                 C  s   t |tƒstS t| ƒt|ƒkS r   )r=   r   ÚNotImplementedr2   ©r—   r¦   r!   r!   r"   Ú__eq__„  s    
zMarker.__eq__c                 C  s   t | ƒS r   )r2   rž   r!   r!   r"   Ú__getstate__Š  s    zMarker.__getstate__)Ústater   c              
   C  sà   t |tƒrTztt|ƒƒ| _W n2 tk
rN } ztd|›�ƒ|‚W 5 d }~X Y nX d S t |tƒr‚d|kr‚|d }t |tƒr‚|| _d S t |t	ƒrÎt
|ƒdkrÎ|\}}t |tƒrÎd|krÎ|d }t |tƒrÎ|| _d S td|›�ƒ‚d S )NzCannot restore Marker from r”   rˆ   )r=   r2   rH   r–   r”   r   ry   ÚdictrS   r>   rU   )r—   r«   Úexcrp   Ú_Z	slot_dictr!   r!   r"   Ú__setstate__�  s&    
"

zMarker.__setstate__c                 C  s"   t |tƒstS |  | jd|jg¡S )Nrt   ©r=   r   r§   r�   r”   r¨   r!   r!   r"   Ú__and__§  s    
zMarker.__and__c                 C  s"   t |tƒstS |  | jd|jg¡S )Nrs   r°   r¨   r!   r!   r"   Ú__or__¬  s    
zMarker.__or__Nr$   z+Mapping[str, str | AbstractSet[str]] | Noner   )rq   Úcontextr   c                 C  s„   t dtƒ ƒ}|dkr(|jtƒ tƒ d� n|dkr8d|d< |dk	rt| |¡ d|krtt d|d ƒ}|rlt|ƒnd|d< t| jt|ƒƒS )	a"  Evaluate a marker.

        Return the boolean from evaluating this marker against the environment.
        The environment is determined from the current Python process unless
        passed in explicitly.

        :param environment: Mapping containing keys and values to override the
           detected environment.
        :param EvaluateContext context: The context in which the marker is
            evaluated, which influences what marker names are considered valid.
            Accepted values are ``"metadata"`` (for core metadata; default),
            ``"lock_file"``, and ``"requirement"`` (i.e. all other situations).
        :raises UndefinedComparison: If the marker uses a comparison on values
            that are not valid versions per the :ref:`specification of version
            specifiers <pypug:version-specifiers>`.
        :raises UndefinedEnvironmentName: If the marker references a value that
            is missing from the evaluation environment.
        :returns: ``True`` if the marker matches, otherwise ``False``.

        ro   r%   )r'   r(   r$   Ú r<   Nz
str | None)r	   r   ÚupdateÚ	frozensetr   rx   r”   Ú_repair_python_full_version)r—   rq   r³   Úcurrent_environmentr<   r!   r!   r"   Úevaluate±  s(     ÿ ÿ
 ÿzMarker.evaluate)Nr$   )r.   r/   r0   r1   Ú	__slots__r™   Úclassmethodr�   rŸ   r¡   r¤   r©   rª   r¯   r±   r²   r¹   r!   r!   r!   r"   r   =  s    	  ý)Úenvr   c                 C  s*   t d| d ƒ}| d¡r&|› d�| d< | S )zƒ
    Work around platform.python_version() returning something that is not PEP 440
    compliant for non-tagged Python builds.
    r2   r+   ú+Úlocal)r	   Úendswith)r¼   r+   r!   r!   r"   r·   â  s    
r·   )T)8Ú
__future__r   ÚoperatorrŒ   r�   r‰   Útypingr   r   r   r   r   r   r	   Ú_parserr   r   r   r   r   r   r–   Ú
_tokenizerr   Ú
specifiersr   r   Úutilsr   r    r#   r2   ra   ZOperatorr   rm   re   Ú
ValueErrorr   r   r   r   rC   rH   rK   ÚeqÚner`   r:   rj   rn   rx   r‡   r   r   r·   r!   r!   r!   r"   Ú<module>   sj    $ù
ü	M	 ÿø! &