o
    Zh                     @   sD  d 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dlmZ ddlmZ d	d
gZG dd dejZejddG dd dZG dd
 d
eZG dd dZdZdedejfddZdedejfddZdedejfddZdedejf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)NoReturn)Optional)Sequence
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   N/var/www/html/lang_env/lib/python3.10/site-packages/_pytest/mark/expression.pyr
   %   s    r
   T)frozenc                   @   s*   e Zd ZU dZeed< eed< eed< dS )Token)typevalueposr   r   r   N)r   r   r   	__slots__r
   __annotations__strintr   r   r   r   r   /   s
   
 r   c                   @   s4   e Zd ZdZdededdfddZdefdd	ZdS )
r	   zThe expression contains invalid syntax.

    :param column: The column in the line where the error occurred (1-based).
    :param message: A description of the error.
    columnmessagereturnNc                 C   s   || _ || _d S Nr$   r%   )selfr$   r%   r   r   r   __init__>   s   
zParseError.__init__c                 C   s   d| j  d| j S )Nz
at column z: r(   r)   r   r   r   __str__B   s   zParseError.__str__)r   r   r   __doc__r#   r"   r*   r,   r   r   r   r   r	   7   s    c                   @   sn   e Zd ZdZdeddfddZdedee fddZd	d
de	de
dee fddZdee	 defddZdS )Scanner)tokenscurrentinputr&   Nc                 C   s   |  || _t| j| _d S r'   )lexr/   nextr0   )r)   r1   r   r   r   r*   I   s   zScanner.__init__c                 c   s<   d}|t |k r|| dv r|d7 }nz|| dkr'ttjd|V  |d7 }ng|| dkr:ttjd|V  |d7 }nTtd||d  }|r|d}|dkrXttj||V  n"|dkrettj	||V  n|d	krrttj
||V  nttj||V  |t |7 }nt|d d
||  d|t |k s	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	   r   )r)   r1   r   r=   r   r   r   r   r2   M   s8   



zScanner.lexFrejectr   r@   c                C   sB   | j j|u r| j }|jtjurt| j| _ |S |r| |f d S r'   )r0   r   r
   r   r3   r/   r@   )r)   r   r@   tokenr   r   r   acceptl   s   zScanner.acceptexpectedc                 C   s0   t | jjd dddd |D | jjj)Nr6   zexpected {}; got {}z OR c                 s   s    | ]}|j V  qd S r'   )r   ).0r   r   r   r   	<genexpr>z   s    z!Scanner.reject.<locals>.<genexpr>)r	   r0   r   formatjoinr   r   )r)   rC   r   r   r   r@   v   s   
zScanner.reject)r   r   r   r    r"   r*   r   r   r2   r
   boolr   rB   r   r   r@   r   r   r   r   r.   F   s     
r.   $sr&   c                 C   s@   |  tjrtd}nt| }| j tjdd tt|S )NFTr?   )rB   r
   r   astConstantexprfix_missing_locationsr   )rJ   retr   r   r   
expression   s
   rP   c                 C   @   t | }| tjrt | }tt ||g}| tjs
|S r'   )and_exprrB   r
   r   rK   BoolOpOrrJ   rO   rhsr   r   r   rM         rM   c                 C   rQ   r'   )not_exprrB   r
   r   rK   rS   AndrU   r   r   r   rR      rW   rR   c                 C   s   |  tjrtt t| S |  tjr$t| }| j tj	dd |S |  tj
}|r7tt|j t S | tjtjtj
f d S )NTr?   )rB   r
   r   rK   UnaryOpNotrX   r   rM   r   r   NameIDENT_PREFIXr   Loadr@   )rJ   rO   identr   r   r   rX      s   rX   c                   @   s^   e Zd ZdZdeegef ddfddZdedefdd	Zde	e fd
dZ
defddZdS )MatcherAdapterzDAdapts a matcher function to a locals mapping as required by eval().matcherr&   Nc                 C   
   || _ d S r'   )ra   )r)   ra   r   r   r   r*         
zMatcherAdapter.__init__keyc                 C   s   |  |ttd  S r'   )ra   r;   r]   )r)   rd   r   r   r   __getitem__   s   zMatcherAdapter.__getitem__c                 C      t  r'   NotImplementedErrorr+   r   r   r   __iter__      zMatcherAdapter.__iter__c                 C   rf   r'   rg   r+   r   r   r   __len__   rj   zMatcherAdapter.__len__)r   r   r   r-   r   r"   rH   r*   re   r   ri   r#   rk   r   r   r   r   r`      s    r`   c                   @   sZ   e Zd ZdZdZdejddfddZede	dd fd	d
Z
dee	gef defddZdS )r   zwA compiled match expression as used by -k and -m.

    The expression can be evaluated against different matchers.
    coderm   r&   Nc                 C   rb   r'   rl   )r)   rm   r   r   r   r*      rc   zExpression.__init__r1   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)rP   r.   compiler   )r)   r1   Zastexprrm   r   r   r   rq      s   zExpression.compilera   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   r`   )r)   ra   rO   r   r   r   evaluate   s   	zExpression.evaluate)r   r   r   r-   r    typesCodeTyper*   classmethodr"   rq   r   rH   rs   r   r   r   r   r      s     )r-   rK   dataclassesenumr<   rt   typingr   r   r   r   r   r   __all__Enumr
   	dataclassr   	Exceptionr	   r.   r]   r   rP   rM   rR   rX   r"   rH   r`   r   r   r   r   <module>   s6    

=	