o
    v&i+                     @  s  U d Z ddlmZ ddlZddlmZ ddlm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dlmZ ddlmZ ddgZdZded< G dd de	jZejddG dd dZG dd dZdZd5ddZd6d!d"Zd6d#d$Zd6d%d&Z dd'dd(Z!d7d*d+Z"d8d-d.Z#G d/d deZ$ejG d0d1 d1Z%G d2d3 d3ee&e%f Z'eG d4d dZ(dS )9a  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 kwargs?

ident:      (\w|:|\+|-|\.|\[|\]|\\|/)+
kwargs:     ('(' name '=' value ( ', ' name '=' value )*  ')')
name:       a valid ident, but not a reserved keyword
value:      (unescaped) string literal | (-)?[0-9]+ | 'False' | 'True' | 'None'

The semantics are:

- Empty expression evaluates to False.
- ident evaluates to True or False according to a provided matcher function.
- ident with parentheses and keyword arguments evaluates to True or False according to a provided matcher function.
- or/and/not evaluate according to the usual boolean semantics.
    )annotationsN)Iterator)Mapping)Sequence)Final)final)Literal)NoReturn)overload)Protocol
ExpressionExpressionMatcher<pytest match expression>r   	FILE_NAMEc                   @  s4   e Zd ZdZd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 input=zstring literal,N)__name__
__module____qualname__LPARENRPARENORANDNOTIDENTEOFEQUALSTRINGCOMMA r$   r$   ]/var/www/html/karishye-ai-python/venv/lib/python3.10/site-packages/_pytest/mark/expression.pyr   3   s    r   T)frozenc                   @  s*   e Zd ZU dZded< ded< ded< dS )	Token)postypevaluer   r)   strr*   intr(   N)r   r   r   	__slots____annotations__r$   r$   r$   r%   r'   @   s
   
 r'   c                   @  s`   e Zd ZdZdddZd d	d
Zed!ddZeddd"ddZddd#ddZd$ddZdS )%Scanner)currentinputtokensr1   r+   returnNonec                 C  s"   || _ | || _t| j| _d S N)r1   lexr2   nextr0   )selfr1   r$   r$   r%   __init__K   s   zScanner.__init__Iterator[Token]c                 c  s.   d}|t |k r|| dv r|d7 }n|| dkr(ttjd|V  |d7 }n|| dkr;ttjd|V  |d7 }n|| dkrNttjd|V  |d7 }n|| dkrattjd|V  |d7 }n||  }dv r|||d }|d	krtd
| dt	d|d |f|||d  }|d }d	krtdt	d|d |fttj
||V  |t |7 }nXtd||d  }|r|d}|dkrttj||V  n"|dkrttj||V  n|dkrttj||V  nttj||V  |t |7 }ntd||  dt	d|d |f|t |k s
ttjd|V  d S )Nr   ) 	   ()r   r   )'"zclosing quote "z" is missing\z4escaping with "\" not supported in marker expressionz(:?\w|:|\+|-|\.|\[|\]|\\|/)+r   r   r   zunexpected character "rA    )lenr'   r   r   r   r!   r#   findSyntaxErrorr   r"   rematchgroupr   r   r   r   r    )r8   r1   r(   
quote_charend_quote_posr*   backslash_posrI   r$   r$   r%   r6   P   sb   






0zScanner.lexr)   r   rejectLiteral[True]r'   c                C     d S r5   r$   r8   r)   rN   r$   r$   r%   accept   s   zScanner.acceptFrN   Literal[False]Token | Nonec                C  rP   r5   r$   rQ   r$   r$   r%   rR      s   boolc                C  sB   | j j|u r| j }|jtjurt| j| _ |S |r| |f d S r5   )r0   r)   r   r    r7   r2   rN   )r8   r)   rN   tokenr$   r$   r%   rR      s   expectedSequence[TokenType]r	   c                 C  s:   t dddd |D | jjjtd| jjd | jf)Nzexpected {}; got {}z OR c                 s  s    | ]}|j V  qd S r5   )r*   ).0r)   r$   r$   r%   	<genexpr>   s    z!Scanner.reject.<locals>.<genexpr>r=   )	rG   formatjoinr0   r)   r*   r   r(   r1   )r8   rX   r$   r$   r%   rN      s   zScanner.rejectN)r1   r+   r3   r4   )r1   r+   r3   r:   )r)   r   rN   rO   r3   r'   )r)   r   rN   rT   r3   rU   )r)   r   rN   rV   r3   rU   )rX   rY   r3   r	   )	r   r   r   r-   r9   r6   r
   rR   rN   r$   r$   r$   r%   r/   H   s    

4
r/   $sr3   ast.Expressionc                 C  s@   |  tjrtd}nt| }| j tjdd tt|S )NFTrS   )rR   r   r    astConstantexprfix_missing_locationsr   r_   retr$   r$   r%   
expression   s
   rg   ast.exprc                 C  @   t | }| tjrt | }tt ||g}| tjs
|S r5   )and_exprrR   r   r   ra   BoolOpOrr_   rf   rhsr$   r$   r%   rc         rc   c                 C  ri   r5   )not_exprrR   r   r   ra   rk   Andrm   r$   r$   r%   rj      ro   rj   c                 C  s   |  tjrtt t| S |  tjr$t| }| j tj	dd |S |  tj
}|rUtt|j t }|  tjrQtj|g t| d}| j tj	dd |S |}|S | tjtjtj
f d S )NTrS   )funcargskeywords)rR   r   r   ra   UnaryOpNotrp   r   rc   r   r   NameIDENT_PREFIXr*   LoadCall
all_kwargsrN   )r_   rf   identnamer$   r$   r%   rp      s    rp   F)TrueFalser4   ast.keywordc                 C  s0  | j tjdd}|j std|j td|jd | jft	
|jr6td|j dtd|jd | jf| j tjdd |  tj }rN|jdd }n>| j tjdd}|j } sj|dro|dd   rot|}n|jtv rzt|j }ntd	|j d
td|jd | jft	|jt|}|S )NTrS   znot a valid python identifier r=   z$unexpected reserved python keyword ``rB   -zunexpected character/s "rA   )rR   r   r   r*   isidentifierrG   r   r(   r1   keyword	iskeywordr!   r"   isdigit
startswithr,   BUILTIN_MATCHERSra   rb   )r_   keyword_namevalue_tokenr*   numberrf   r$   r$   r%   single_kwarg   s:   



r   list[ast.keyword]c                 C  s4   t | g}| tjr|t |  | tjs|S r5   )r   rR   r   r#   appendre   r$   r$   r%   r{      s
   
r{   c                   @  s   e Zd ZdZddd	Zd
S )r   aC  A callable which, given an identifier and optional kwargs, should return
    whether it matches in an :class:`Expression` evaluation.

    Should be prepared to handle arbitrary strings as input.

    If no kwargs are provided, the expression of the form `foo`.
    If kwargs are provided, the expression is of the form `foo(1, b=True, "s")`.

    If the expression is not supported (e.g. don't want to accept the kwargs
    syntax variant), should raise :class:`~pytest.UsageError`.

    Example::

        def matcher(name: str, /, **kwargs: str | int | bool | None) -> bool:
            # Match `cat`.
            if name == "cat" and not kwargs:
                return True
            # Match `dog(barks=True)`.
            if name == "dog" and kwargs == {"barks": False}:
                return True
            return False
    r}   r+   kwargsstr | int | bool | Noner3   rV   c                K  rP   r5   r$   )r8   r}   r   r$   r$   r%   __call__  s    zExpressionMatcher.__call__N)r}   r+   r   r   r3   rV   )r   r   r   __doc__r   r$   r$   r$   r%   r      s    c                   @  s2   e Zd ZU ded< ded< dddZdddZdS )MatcherNameAdapterr   matcherr+   r}   r3   rV   c                 C  s   |  | jS r5   r   r}   r8   r$   r$   r%   __bool__  s   zMatcherNameAdapter.__bool__r   r   c                 K  s   | j | jfi |S r5   r   )r8   r   r$   r$   r%   r   "  s   zMatcherNameAdapter.__call__N)r3   rV   )r   r   r3   rV   )r   r   r   r.   r   r   r$   r$   r$   r%   r     s
   
 
r   c                   @  s8   e Zd ZdZdddZdddZdddZdddZdS )MatcherAdapterzDAdapts a matcher function to a locals mapping as required by eval().r   r   r3   r4   c                 C  s
   || _ d S r5   )r   r8   r   r$   r$   r%   r9   )  s   
zMatcherAdapter.__init__keyr+   r   c                 C  s   t | j|ttd  dS )Nr   )r   r   rE   rx   )r8   r   r$   r$   r%   __getitem__,  s   zMatcherAdapter.__getitem__Iterator[str]c                 C     t  r5   NotImplementedErrorr   r$   r$   r%   __iter__/     zMatcherAdapter.__iter__r,   c                 C  r   r5   r   r   r$   r$   r%   __len__2  r   zMatcherAdapter.__len__N)r   r   r3   r4   )r   r+   r3   r   )r3   r   )r3   r,   )r   r   r   r   r9   r   r   r   r$   r$   r$   r%   r   &  s    


r   c                   @  s6   e Zd ZdZdZdd	d
ZedddZdddZdS )r   zwA compiled match expression as used by -k and -m.

    The expression can be evaluated against different matchers.
    )_coder1   r1   r+   codetypes.CodeTyper3   r4   c                 C  s   || _ || _d S r5   )r1   r   )r8   r1   r   r$   r$   r%   r9   ?  s   
zExpression.__init__c                 C  s$   t t|}t|ddd}t||S )zCompile a match expression.

        :param input: The input expression - one line.

        :raises SyntaxError: If the expression is malformed.
        r   eval)filenamemode)rg   r/   compiler   )clsr1   astexprr   r$   r$   r%   r   D  s   
zExpression.compiler   r   rV   c                 C  s   t t| jdi it|S )a  Evaluate the match expression.

        :param matcher:
            A callback which determines whether an identifier matches or not.
            See the :class:`ExpressionMatcher` protocol for details and example.

        :returns: Whether the expression matches or not.

        :raises UsageError:
            If the matcher doesn't support the expression. Cannot happen if the
            matcher supports all expressions.
        __builtins__)rV   r   r   r   r   r$   r$   r%   evaluateT  s   zExpression.evaluateN)r1   r+   r   r   r3   r4   )r1   r+   r3   r   )r   r   r3   rV   )	r   r   r   r   r-   r9   classmethodr   r   r$   r$   r$   r%   r   6  s    
)r_   r/   r3   r`   )r_   r/   r3   rh   )r_   r/   r3   r   )r_   r/   r3   r   ))r   
__future__r   ra   collections.abcr   r   r   dataclassesenumr   rH   typestypingr   r   r   r	   r
   r   __all__r   r.   Enumr   	dataclassr'   r/   rx   rg   rc   rj   rp   r   r   r{   r   r   r+   r   r   r$   r$   r$   r%   <module>   sN    
[

	



"