o
    hk                     @   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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 ejd	krGejZnej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   M/var/www/html/ai/venv/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   4   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__C   s   
zParseError.__init__c                 C   s   d| j  d| j S )Nz
at column z: r*   r+   r   r   r   __str__G   s   zParseError.__str__)r   r   r   __doc__r%   r$   r,   r.   r   r   r   r   r   <   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)   )lexr1   nextr2   )r+   r3   r   r   r   r,   N   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+   r3   r!   r?   r    r   r   r   r4   R   s8   



zScanner.lexFrejectr   rB   c                C   sB   | j j|u r| j }|jtjurt| j| _ |S |r| |f d S r)   )r2   r   r   r   r5   r1   rB   )r+   r   rB   tokenr   r   r   acceptq   s   zScanner.acceptexpectedc                 C   s0   t | jjd dddd |D | jjj)Nr8   zexpected {}; got {}z OR c                 s   s    | ]}|j V  qd S r)   )r    ).0r   r   r   r   	<genexpr>   s    z!Scanner.reject.<locals>.<genexpr>)r   r2   r!   formatjoinr   r    )r+   rE   r   r   r   rB   {   s   
zScanner.reject)r   r   r   r"   r$   r,   r   r   r4   r   boolr   rD   r   r   rB   r   r   r   r   r0   K   s     
r0   $sr(   c                 C   s>   |  tjrtd}nt| }| j tjdd tt|S )NFTrA   )rD   r   r   astNameConstantexprastfix_missing_locationsr
   )rL   retr   r   r   
expression   s
   
rR   c                 C   @   t | }| tjrt | }tt ||g}| tjs
|S r)   )and_exprrD   r   r   rO   BoolOpOrrL   rQ   rhsr   r   r   rN         rN   c                 C   rS   r)   )not_exprrD   r   r   rO   rU   AndrW   r   r   r   rT      rY   rT   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 )NTrA   )rD   r   r   rO   UnaryOpNotrZ   r   rN   r   r   NameIDENT_PREFIXr    LoadrB   )rL   rQ   identr   r   r   rZ      s   rZ   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)   )rc   )r+   rc   r   r   r   r,         
zMatcherAdapter.__init__keyc                 C   s   |  |ttd  S r)   )rc   r=   r_   )r+   rf   r   r   r   __getitem__   s   zMatcherAdapter.__getitem__c                 C      t  r)   NotImplementedErrorr-   r   r   r   __iter__      zMatcherAdapter.__iter__c                 C   rh   r)   ri   r-   r   r   r   __len__   rl   zMatcherAdapter.__len__)r   r   r   r/   r   r$   rJ   r,   rg   r   rk   r%   rm   r   r   r   r   rb      s    rb   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.
    codero   r(   Nc                 C   rd   r)   rn   )r+   ro   r   r   r   r,      re   zExpression.__init__r3   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)rR   r0   compiler
   )r+   r3   astexprro   r   r   r   rs      s   zExpression.compilerc   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__)rp   ro   rb   )r+   rc   rQ   r   r   r   evaluate   s   	zExpression.evaluate)r   r   r   r/   r"   typesCodeTyper,   classmethodr$   rs   r   rJ   rv   r   r   r   r   r
      s     )#r/   rO   dataclassesenumr>   sysrw   typingr   r   r   r   r   r   version_infoConstantrM   NameConstant__all__Enumr   	dataclassr   	Exceptionr   r0   r_   r
   rR   rN   rT   rZ   r$   rJ   rb   r   r   r   r   <module>   s>    


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