
    {i+                    8   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e	j                  Z ej        d           G d d                      Z G d d          ZdZd/dZd0d Zd0d!Zd0d"Z dd#dd$Z!d1d&Z"d2d(Z# G d) de          Z$ej         G d* d+                      Z% G d, d-ee&e%f                   Z'e G d. d                      Z(dS )3a  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                  6    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     Z/root/projects/openclaw-proxy/venv/lib/python3.11/site-packages/_pytest/mark/expression.pyr   r   3   s@        F F	B
C
CE
CEFEEEr'   r   T)frozenc                  2    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+   @   s0         (IOOOJJJHHHHHr'   r+   c                  n    e Zd ZdZddZddZedd            Zedddd            ZddddZd dZdS )!Scanner)currentinputtokensr6   r/   returnNonec                z    || _         |                     |          | _        t          | j                  | _        d S N)r6   lexr7   nextr5   )selfr6   s     r(   __init__zScanner.__init__K   s/    
hhuooDK((r'   Iterator[Token]c              #    K   d}|t          |          k     r||         dv r|dz  }nu||         dk    r$t          t          j        d|          V  |dz  }nE||         dk    r$t          t          j        d|          V  |dz  }n||         dk    r$t          t          j        d|          V  |dz  }n||         dk    r$t          t          j        d|          V  |dz  }n||         x}dv r|                    ||dz             }|d	k    r t          d
| dt          d|dz   |f          |||dz            }|                    d          x}d	k    rt          dt          d|dz   |f          t          t          j
        ||          V  |t          |          z  }nt          j        d||d                    }|r|                    d          }|dk    rt          t          j        ||          V  ne|dk    rt          t          j        ||          V  nA|dk    rt          t          j        ||          V  nt          t          j        ||          V  |t          |          z  }n&t          d||          dt          d|dz   |f          |t          |          k     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 "rH    )lenr+   r   r   r   r#   r%   findSyntaxErrorr   r$   rematchgroupr   r   r    r!   r"   )r>   r6   r,   
quote_charend_quote_posr.   backslash_posrP   s           r(   r<   zScanner.lexP   s/     CJJSz[((qss""I,c377777qss""I,c377777qss""IOS#66666qss""IOS#66666q %c
**z99 %

:sQw ? ? B&&%B*BBB"AsQw6   cMA$556%*ZZ%5%55M"<<%O"A}q'8%@   I,eS99999s5zz!!@%+NN !KKNNE}}#IL%======%#IM5#>>>>>>%#IM5#>>>>>>#IOUC@@@@@3u::%CC%>s>>>"AsQw6  Y CJJ` IM2s+++++++r'   r-   r   rejectLiteral[True]r+   c                   d S r;   r&   r>   r-   rU   s      r(   acceptzScanner.accept   s    JM#r'   FrU   Literal[False]Token | Nonec                   d S r;   r&   rX   s      r(   rY   zScanner.accept   s	     sr'   boolc                   | j         j        |u r5| j         }|j        t          j        urt	          | j                  | _         |S |r|                     |f           d S r;   )r5   r-   r   r"   r=   r7   rU   )r>   r-   rU   tokens       r(   rY   zScanner.accept   s_    <$$LEz..#DK00L 	!KK   tr'   expectedSequence[TokenType]r
   c                    t          d                    d                    d |D                       | j        j        j                  t          d| j        j        dz   | j        f          )Nzexpected {}; got {}z OR c              3  $   K   | ]}|j         V  d S r;   )r.   ).0r-   s     r(   	<genexpr>z!Scanner.reject.<locals>.<genexpr>   s$      <<4DJ<<<<<<r'   rD   )	rN   formatjoinr5   r-   r.   r   r,   r6   )r>   ra   s     r(   rU   zScanner.reject   sj    !((<<8<<<<<!'  4<+a/<
 
 	
r'   N)r6   r/   r8   r9   )r6   r/   r8   r@   )r-   r   rU   rV   r8   r+   )r-   r   rU   r[   r8   r\   )r-   r   rU   r^   r8   r\   )ra   rb   r8   r
   )	r   r   r   r1   r?   r<   r   rY   rU   r&   r'   r(   r4   r4   H   s        .I) ) ) )
2, 2, 2, 2,h MMM XM;@     X 9>      
 
 
 
 
 
r'   r4   $sr8   ast.Expressionc                   |                      t          j                  rt          j        d          }n0t          |           }|                      t          j        d           t          j        t          j        |                    S )NFTrZ   )rY   r   r"   astConstantexprfix_missing_locationsr   rj   rets     r(   
expressionrs      sg    xx	 -U++1gg	t,,,$S^C%8%8999r'   ast.exprc                   t          |           }|                     t          j                  rVt          |           }t	          j        t	          j                    ||g          }|                     t          j                  V|S r;   )and_exprrY   r   r   rm   BoolOpOrrj   rr   rhss      r(   ro   ro      sh    
1++C
((9<
 
  /qkkjC:.. ((9<
 
  / Jr'   c                   t          |           }|                     t          j                  rVt          |           }t	          j        t	          j                    ||g          }|                     t          j                  V|S r;   )not_exprrY   r   r   rm   rw   Andry   s      r(   rv   rv      sh    
1++C
((9=
!
! 0qkkjS#J// ((9=
!
! 0 Jr'   c                2   |                      t          j                  r3t          j        t          j                    t          |                     S |                      t          j                  r2t          |           }|                      t          j	        d           |S |                      t          j
                  }|rt          j        t          |j        z   t          j                              }|                      t          j                  rFt          j        |g t!          |                     }|                      t          j	        d           n|}|S |                     t          j        t          j        t          j
        f           d S )NTrZ   )funcargskeywords)rY   r   r    rm   UnaryOpNotr|   r   ro   r   r!   NameIDENT_PREFIXr.   LoadCall
all_kwargsrU   )rj   rr   identnames       r(   r|   r|      s.   xx	 3{3799hqkk222xx	 !! 1gg	!$///
HHY_%%E xu{2CHJJ??88I$%% 	(2
1FFFCHHY%dH3333C
HHimY-y?@@@@@r'   F)TrueFalser9   ast.keywordc                   |                      t          j        d          }|j                                        s.t          d|j         t          d|j        dz   | j        f          t          j
        |j                  r/t          d|j         dt          d|j        dz   | j        f          |                      t          j        d           |                      t          j                  x}r|j        dd         }n|                      t          j        d          }|j        x}                                s1|                    d          r,|dd                                          rt          |          }nP|j        t           v rt           |j                 }n/t          d	|j         d
t          d|j        dz   | j        f          t#          j	        |j        t#          j        |                    }|S )NTrZ   znot a valid python identifier rD   z$unexpected reserved python keyword ``rI   -zunexpected character/s "rH   )rY   r   r!   r.   isidentifierrN   r   r,   r6   keyword	iskeywordr#   r$   isdigit
startswithr0   BUILTIN_MATCHERSrm   rn   )rj   keyword_namevalue_tokenr.   numberrr   s         r(   single_kwargr      s   88IOD899L**,, 
A\-?AA<+a/9
 
 	
 +,, 
H<3EHHH<+a/9
 
 	
 HHY_TH***hhy/000{ )4):1R4)@hhyth<<!''F0022 
	c""
	'-abbz'9'9';';
	 KKEE"222$[%67EE?;+<???A{2AG<  
 +l(#,u*=*=
>
>CJr'   list[ast.keyword]c                    t          |           g}|                     t          j                  rA|                    t          |                      |                     t          j                  A|S r;   )r   rY   r   r%   appendrq   s     r(   r   r      s[    ??
C
((9?
#
# $

<??### ((9?
#
# $Jr'   c                      e Zd ZdZ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 | Noner8   r^   c                   d S r;   r&   )r>   r   r   s      r(   __call__zExpressionMatcher.__call__  s      r'   N)r   r/   r   r   r8   r^   )r   r   r   __doc__r   r&   r'   r(   r   r      s)         . UTTTTTr'   c                  4    e Zd ZU ded<   ded<   ddZdd
ZdS )MatcherNameAdapterr   matcherr/   r   r8   r^   c                6    |                      | j                  S r;   r   r   r>   s    r(   __bool__zMatcherNameAdapter.__bool__  s    ||DI&&&r'   r   r   c                (     | j         | j        fi |S r;   r   )r>   r   s     r(   r   zMatcherNameAdapter.__call__"  s    t|DI00000r'   N)r8   r^   )r   r   r8   r^   )r   r   r   r2   r   r   r&   r'   r(   r   r     sS         III' ' ' '1 1 1 1 1 1r'   r   c                  2    e Zd ZdZddZdd
ZddZddZdS )MatcherAdapterzDAdapts a matcher function to a locals mapping as required by eval().r   r   r8   r9   c                    || _         d S r;   )r   r>   r   s     r(   r?   zMatcherAdapter.__init__)  s    r'   keyr/   r   c                b    t          | j        |t          t                    d                    S )Nr   )r   r   rL   r   )r>   r   s     r(   __getitem__zMatcherAdapter.__getitem__,  s*    !$,S\ARARATAT=UVVVVr'   Iterator[str]c                    t                      r;   NotImplementedErrorr   s    r(   __iter__zMatcherAdapter.__iter__/      !###r'   r0   c                    t                      r;   r   r   s    r(   __len__zMatcherAdapter.__len__2  r   r'   N)r   r   r8   r9   )r   r/   r8   r   )r8   r   )r8   r0   )r   r   r   r   r?   r   r   r   r&   r'   r(   r   r   &  sn        NN   W W W W$ $ $ $$ $ $ $ $ $r'   r   c                  >    e Zd ZdZdZdd	Zedd
            ZddZdS )r   zwA compiled match expression as used by -k and -m.

    The expression can be evaluated against different matchers.
    )_coder6   r6   r/   codetypes.CodeTyper8   r9   c                "    || _         || _        d S r;   )r6   r   )r>   r6   r   s      r(   r?   zExpression.__init__?  s    !
 


r'   c                ~    t          t          |                    }t          |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)rs   r4   compiler   )clsr6   astexprr   s       r(   r   zExpression.compileD  sF     WU^^,,0
 
 

 %&&&r'   r   r   r^   c           	     f    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__)r^   r   r   r   r   s     r(   evaluatezExpression.evaluateT  s-     Dnb%9>';R;RSSTTTr'   N)r6   r/   r   r   r8   r9   )r6   r/   r8   r   )r   r   r8   r^   )	r   r   r   r   r1   r?   classmethodr   r   r&   r'   r(   r   r   6  ss         
 #I! ! ! !
 ' ' ' ['U U U U U Ur'   )rj   r4   r8   rk   )rj   r4   r8   rt   )rj   r4   r8   r   )rj   r4   r8   r   ))r   
__future__r   rm   collections.abcr   r   r   dataclassesenumr   rO   typestypingr   r   r	   r
   r   r   __all__r   r2   Enumr   	dataclassr+   r4   r   rs   ro   rv   r|   r   r   r   r   r   r/   r   r   r&   r'   r(   <module>r      sD    , # " " " " " 



 $ $ $ $ $ $ # # # # # # $ $ $ $ $ $       				                                       /	 . . . .
 
 
 
 
	 
 
 
 d###       $#U
 U
 U
 U
 U
 U
 U
 U
v : : : :      A A A A( !5$??    D   U U U U U U U U6 1 1 1 1 1 1 1 1$ $ $ $ $WS"445 $ $ $  *U *U *U *U *U *U *U *U *U *Ur'   