a
    /§»aä  ã                   @   sN  d 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dlm
Z
 ddlmZ ddlZer„dd	lmZ d
dgZG dd„ dejƒZejddd�G dd„ dƒƒZG dd„ deƒZG dd„ dƒZdZeejdœdd„Zeejdœdd„Zeejdœdd„Zeejdœdd„ZG dd „ d eeef ƒZG d!d
„ d
ƒZdS )"aÈ  Evaluate match expressions, as used by `-k` and `-m`.

The grammar is:

expression: expr? EOF
expr:       and_expr ('or' and_expr)*
and_expr:   not_expr ('and' not_expr)*
not_expr:   'not' not_expr | '(' expr ')' | ident
ident:      (\w|:|\+|-|\.|\[|\])+

The semantics are:

- Empty expression evaluates to False.
- ident evaluates to True of False according to a provided matcher function.
- or/and/not evaluate according to the usual boolean semantics.
é    N)ÚCallable)ÚIterator)ÚMapping)ÚOptional)ÚSequence)ÚTYPE_CHECKING)ÚNoReturnÚ
ExpressionÚ
ParseErrorc                   @   s(   e Zd ZdZdZdZdZdZdZdZ	dS )	Ú	TokenTypezleft parenthesiszright parenthesisÚorÚandÚnotÚ
identifierzend of inputN)
Ú__name__Ú
__module__Ú__qualname__ÚLPARENÚRPARENÚORÚANDÚNOTÚIDENTÚEOF© r   r   úQ/home/yuhw/wc/pochoir/venv/lib/python3.9/site-packages/_pytest/mark/expression.pyr   (   s   r   T)ÚfrozenÚslotsc                   @   s0   e Zd Zejed�Zejed�Zeje	d�Z
dS )ÚToken)ÚtypeN)r   r   r   ÚattrÚibr   r   ÚstrÚvalueÚintÚposr   r   r   r   r   2   s   r   c                   @   s0   e Zd ZdZeeddœdd„Zedœdd„ZdS )	r
   z«The expression contains invalid syntax.

    :param column: The column in the line where the error occurred (1-based).
    :param message: A description of the error.
    N)ÚcolumnÚmessageÚreturnc                 C   s   || _ || _d S ©N©r&   r'   )Úselfr&   r'   r   r   r   Ú__init__@   s    zParseError.__init__©r(   c                 C   s   d| j › d| j› �S )Nz
at column z: r*   ©r+   r   r   r   Ú__str__D   s    zParseError.__str__)r   r   r   Ú__doc__r$   r"   r,   r/   r   r   r   r   r
   9   s   c                   @   sd   e Zd ZdZeddœdd„Zeee dœdd„Zdd	œe	e
ee d
œdd„Zee	 ddœdd„ZdS )ÚScanner)ÚtokensÚcurrentN©Úinputr(   c                 C   s   |   |¡| _t| jƒ| _d S r)   )Úlexr2   Únextr3   )r+   r5   r   r   r   r,   K   s    zScanner.__init__c                 c   s2  d}|t |ƒk �r|| dv r(|d7 }q|| dkrNttjd|ƒV  |d7 }q|| dkrtttjd|ƒV  |d7 }qt d||d … ¡}|�r| d¡}|dkr²ttj||ƒV  nD|dkrÌttj	||ƒV  n*|d	krættj
||ƒV  nttj||ƒV  |t |ƒ7 }qt|d d
 || ¡ƒ‚qttjd|ƒV  d S )Nr   )ú ú	é   ú(ú)z(:?\w|:|\+|-|\.|\[|\])+r   r   r   zunexpected character "{}"Ú )Úlenr   r   r   r   ÚreÚmatchÚgroupr   r   r   r   r
   Úformatr   )r+   r5   r%   r@   r#   r   r   r   r6   O   s2    



ÿzScanner.lexF©Úreject)r   rD   r(   c                C   sB   | j j|u r.| j }|jtjur*t| jƒ| _ |S |r>|  |f¡ d S r)   )r3   r   r   r   r7   r2   rD   )r+   r   rD   Útokenr   r   r   Úacceptm   s    zScanner.acceptr   )Úexpectedr(   c                 C   s4   t | jjd d d dd„ |D ƒ¡| jjj¡ƒ‚d S )Nr:   zexpected {}; got {}z OR c                 s   s   | ]}|j V  qd S r)   )r#   )Ú.0r   r   r   r   Ú	<genexpr>{   ó    z!Scanner.reject.<locals>.<genexpr>)r
   r3   r%   rB   Újoinr   r#   )r+   rG   r   r   r   rD   w   s    
ÿþzScanner.reject)r   r   r   Ú	__slots__r"   r,   r   r   r6   r   Úboolr   rF   r   rD   r   r   r   r   r1   H   s
   
r1   ú$)Úsr(   c                 C   s@   |   tj¡rt d¡}nt| ƒ}| j tjdd� t t |¡¡S )NFTrC   )rF   r   r   ÚastÚNameConstantÚexprÚfix_missing_locationsr	   )rO   Úretr   r   r   Ú
expression†   s
    rU   c                 C   s6   t | ƒ}|  tj¡r2t | ƒ}t t ¡ ||g¡}q|S r)   )Úand_exprrF   r   r   rP   ÚBoolOpÚOr©rO   rT   Úrhsr   r   r   rR   �   s
    rR   c                 C   s6   t | ƒ}|  tj¡r2t | ƒ}t t ¡ ||g¡}q|S r)   )Únot_exprrF   r   r   rP   rW   ÚAndrY   r   r   r   rV   —   s
    rV   c                 C   sˆ   |   tj¡r t t ¡ t| ƒ¡S |   tj¡rHt| ƒ}| j tj	dd� |S |   tj
¡}|rnt t|j t ¡ ¡S |  tjtjtj
f¡ d S )NTrC   )rF   r   r   rP   ÚUnaryOpÚNotr[   r   rR   r   r   ÚNameÚIDENT_PREFIXr#   ÚLoadrD   )rO   rT   Úidentr   r   r   r[   Ÿ   s    r[   c                   @   sZ   e Zd ZdZeegef ddœdd„Zeedœdd„Ze	e d	œd
d„Z
ed	œdd„ZdS )ÚMatcherAdapterzDAdapts a matcher function to a locals mapping as required by eval().N©Úmatcherr(   c                 C   s
   || _ d S r)   )re   )r+   re   r   r   r   r,   ¯   s    zMatcherAdapter.__init__)Úkeyr(   c                 C   s   |   |ttƒd … ¡S r)   )re   r>   r`   )r+   rf   r   r   r   Ú__getitem__²   s    zMatcherAdapter.__getitem__r-   c                 C   s
   t ƒ ‚d S r)   ©ÚNotImplementedErrorr.   r   r   r   Ú__iter__µ   s    zMatcherAdapter.__iter__c                 C   s
   t ƒ ‚d S r)   rh   r.   r   r   r   Ú__len__¸   s    zMatcherAdapter.__len__)r   r   r   r0   r   r"   rM   r,   rg   r   rj   r$   rk   r   r   r   r   rc   ¬   s
   rc   c                   @   sT   e Zd ZdZdZejddœdd„Zee	d dœdd	„ƒZ
ee	gef ed
œdd„ZdS )r	   zwA compiled match expression as used by -k and -m.

    The expression can be evaulated against different matchers.
    ©ÚcodeN)rm   r(   c                 C   s
   || _ d S r)   rl   )r+   rm   r   r   r   r,   Ä   s    zExpression.__init__r4   c                 C   s"   t t|ƒƒ}t|ddd�}t|ƒS )z\Compile a match expression.

        :param input: The input expression - one line.
        z<pytest match expression>Úeval)ÚfilenameÚmode)rU   r1   Úcompiler	   )r+   r5   Zastexprrm   r   r   r   rq   Ç   s
    ÿzExpression.compilerd   c                 C   s   t | jdi it|ƒƒ}|S )a	  Evaluate the match expression.

        :param matcher:
            Given an identifier, should return whether it matches or not.
            Should be prepared to handle arbitrary strings as input.

        :returns: Whether the expression matches or not.
        Ú__builtins__)rn   rm   rc   )r+   re   rT   r   r   r   ÚevaluateÓ   s    	zExpression.evaluate)r   r   r   r0   rL   ÚtypesÚCodeTyper,   Úclassmethodr"   rq   r   rM   rs   r   r   r   r   r	   ¼   s   )r0   rP   Úenumr?   rt   Útypingr   r   r   r   r   r   r    r   Ú__all__ÚEnumr   rO   r   Ú	Exceptionr
   r1   r`   r	   rU   rR   rV   r[   r"   rM   rc   r   r   r   r   Ú<module>   s8   þ
;	