
    	hk                        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    rej        Znej        Zd
dgZ G d dej                  Z ej        d           G d d                      Z G d de          Z G d d          ZdZdedej        fdZdedej        fdZdedej        fdZdedej        fdZ G d de
e e!f                   Z" G 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                   *    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     d/var/www/html/web-builder-api.evdpl.com/venv/lib/python3.11/site-packages/_pytest/mark/expression.pyr   r   *   s1        F F	B
C
CE
CCCr   r   T)frozenc                   2    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   s0         (I
OOOJJJ	HHHHHr   r"   c                   2    e Zd ZdZdededdfdZdef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                 "    || _         || _        d S Nr+   r,   )selfr+   r,   s      r   __init__zParseError.__init__C   s    r   c                 &    d| j          d| j         S )Nz
at column z: r0   r1   s    r   __str__zParseError.__str__G   s    9DK994<999r   )r   r   r   __doc__r)   r(   r2   r5   r   r   r   r   r   <   sb         s S T    : : : : : : :r   c                       e Zd ZdZdeddfdZdedee         fdZddd	e	d
e
dee         fdZdee	         defdZdS )Scanner)tokenscurrentinputr-   Nc                 l    |                      |          | _        t          | j                  | _        d S r/   )lexr9   nextr:   )r1   r;   s     r   r2   zScanner.__init__N   s(    hhuooDK((r   c              #   R  K   d}|t          |          k     rq||         dv r|dz  }nL||         dk    r$t          t          j        d|          V  |dz  }n||         dk    r#t          t          j        d|          V  |d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z   d
||          d          |t          |          k     qt          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   )r1   r;   r%   rI   r$   s        r   r=   zScanner.lexR   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!@%+NN !KKNNE}}#IL%======%#IM5#>>>>>>%#IM5#>>>>>>#IOUC@@@@@3u::%CC$a>s>>>  / CJJ6 IM2s+++++++r   Frejectr#   rL   c                    | j         j        |u r5| j         }|j        t          j        urt	          | j                  | _         |S |r|                     |f           d S r/   )r:   r#   r   r   r>   r9   rL   )r1   r#   rL   tokens       r   acceptzScanner.acceptq   s_    <$$LEz..#DK00L 	!KK   tr   expectedc           	          t          | j        j        dz   d                    d                    d |D                       | j        j        j                            )NrB   z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   )r   r:   r%   formatjoinr#   r$   )r1   rP   s     r   rL   zScanner.reject{   s]    Lq !((<<8<<<<<!' 
 
 	
r   )r   r   r   r&   r(   r2   r   r"   r=   r   boolr   rO   r   r   rL   r   r   r   r8   r8   K   s        %I)c )d ) ) ) ), ,% , , , ,> 9>   9  (5/    
x	2 
x 
 
 
 
 
 
r   r8   $sr-   c                    |                      t          j                  rt          d          }n0t	          |           }|                      t          j        d           t          j        t          j        |                    S )NFTrK   )rO   r   r   astNameConstantexprastfix_missing_locationsr   )rY   rets     r   
expressionr`      se    xx	 -'..1gg	t,,,$S^C%8%8999r   c                    t          |           }|                     t          j                  rVt          |           }t	          j        t	          j                    ||g          }|                     t          j                  V|S r/   )and_exprrO   r   r   r]   BoolOpOrrY   r_   rhss      r   r\   r\      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_exprrO   r   r   r]   rc   Andre   s      r   rb   rb      sh    
1++C
((9=
!
! 0qkkjS#J// ((9=
!
! 0 Jr   c                 `   |                      t          j                  r3t          j        t          j                    t          |                     S |                      t          j                  r2t          |           }|                      t          j	        d           |S |                      t          j
                  }|r3t          j        t          |j        z   t          j                              S |                     t          j        t          j        t          j
        f           d S )NTrK   )rO   r   r   r]   UnaryOpNotrh   r   r\   r   r   NameIDENT_PREFIXr$   LoadrL   )rY   r_   idents      r   rh   rh      s    xx	 3{3799hqkk222xx	 !! 1gg	!$///
HHY_%%E @xu{2CHJJ???HHimY-y?@@@@@r   c                   h    e Zd ZdZdeegef         ddfdZdedefdZde	e         fdZ
defd	ZdS )
MatcherAdapterzDAdapts a matcher function to a locals mapping as required by eval().matcherr-   Nc                     || _         d S r/   )rs   )r1   rs   s     r   r2   zMatcherAdapter.__init__   s    r   keyc                 `    |                      |t          t                    d                    S r/   )rs   rG   rn   )r1   ru   s     r   __getitem__zMatcherAdapter.__getitem__   s'    ||CL 1 1 3 34555r   c                     t                      r/   NotImplementedErrorr4   s    r   __iter__zMatcherAdapter.__iter__       !###r   c                     t                      r/   ry   r4   s    r   __len__zMatcherAdapter.__len__   r|   r   )r   r   r   r6   r   r(   rW   r2   rw   r   r{   r)   r~   r   r   r   rr   rr      s        NN# 5 $    6s 6t 6 6 6 6$(3- $ $ $ $$ $ $ $ $ $ $r   rr   c                   r    e Zd ZdZdZdej        ddfdZede	dd fd            Z
d	ee	gef         defd
ZdS )r   zwA compiled match expression as used by -k and -m.

    The expression can be evaluated against different matchers.
    coder   r-   Nc                     || _         d S r/   r   )r1   r   s     r   r2   zExpression.__init__   s    			r   r;   c                 |    t          t          |                    }t          |dd          }t          |          S )z\Compile a match expression.

        :param input: The input expression - one line.
        z<pytest match expression>eval)filenamemode)r`   r8   compiler   )r1   r;   astexprr   s       r   r   zExpression.compile   sD     WU^^,,&0 
  
  

 $r   rs   c                 P    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__)r   r   rr   )r1   rs   r_   s      r   evaluatezExpression.evaluate   s)     ^R$8.:Q:QRR
r   )r   r   r   r6   r&   typesCodeTyper2   classmethodr(   r   r   rW   r   r   r   r   r   r      s         
 IU^       S  \       [ 
# 5 
$ 
 
 
 
 
 
r   )#r6   r]   dataclassesenumrH   sysr   typingr   r   r   r   r   r   version_infoConstantr[   NameConstant__all__Enumr   	dataclassr"   	Exceptionr   r8   rn   r   r`   r\   rb   rh   r(   rW   rr   r   r   r   <module>r      s     


      				 



                                     vlOO&O     	    d###       $#: : : : : : : :7
 7
 7
 7
 7
 7
 7
 7
z :' :cn : : : :G      CH    
A 
ACH 
A 
A 
A 
A$ $ $ $ $WS$Y' $ $ $ # # # # # # # # # #r   