a
    ܌xd                     @   s<  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eejdddZeejdddZeejdddZeejd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   O/var/www/html/Ranjet/env/lib/python3.9/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                   @   s0   e Zd ZdZeeddddZed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.
    N)columnmessagereturnc                 C   s   || _ || _d S Nr$   r%   )selfr$   r%   r   r   r   __init__=   s    zParseError.__init__r&   c                 C   s   d| j  d| j S )Nz
at column z: r(   r)   r   r   r   __str__A   s    zParseError.__str__)r   r   r   __doc__r#   r"   r*   r-   r   r   r   r   r	   6   s   c                   @   sd   e Zd ZdZeddddZeee dddZdd	e	e
ee d
ddZee	 edddZdS )Scanner)tokenscurrentNinputr&   c                 C   s   |  || _t| j| _d S r'   )lexr0   nextr1   )r)   r3   r   r   r   r*   H   s    zScanner.__init__c                 c   s4  d}|t |k r || dv r(|d7 }q|| dkrNttjd|V  |d7 }q|| dkrtttjd|V  |d7 }qtd||d  }|r|d}|dkrttj||V  nD|dkrttj	||V  n*|d	krttj
||V  nttj||V  |t |7 }qt|d d
||  dq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   L   s4    



zScanner.lexFreject)r   rB   r&   c                C   sB   | j j|u r.| j }|jtjur*t| j| _ |S |r>| |f d S r'   )r1   r   r
   r   r5   r0   rB   )r)   r   rB   tokenr   r   r   acceptk   s    zScanner.accept)expectedr&   c                 C   s4   t | jjd dddd |D | jjjd S )Nr8   zexpected {}; got {}z OR c                 s   s   | ]}|j V  qd S r'   )r   ).0r   r   r   r   	<genexpr>y       z!Scanner.reject.<locals>.<genexpr>)r	   r1   r   formatjoinr   r   )r)   rE   r   r   r   rB   u   s    
zScanner.reject)r   r   r   r    r"   r*   r   r   r4   r
   boolr   rD   r   r   rB   r   r   r   r   r/   E   s
   
r/   $)sr&   c                 C   s@   |  tjrtd}nt| }| j tjdd tt|S )NFTrA   )rD   r
   r   astNameConstantexprfix_missing_locationsr   )rM   retr   r   r   
expression   s
    rS   c                 C   s6   t | }| tjr2t | }tt ||g}q|S r'   )and_exprrD   r
   r   rN   BoolOpOrrM   rR   rhsr   r   r   rP      s
    rP   c                 C   s6   t | }| tjr2t | }tt ||g}q|S r'   )not_exprrD   r
   r   rN   rU   AndrW   r   r   r   rT      s
    rT   c                 C   s   |  tjr tt t| S |  tjrHt| }| j tj	dd |S |  tj
}|rntt|j t S | tjtjtj
f d S )NTrA   )rD   r
   r   rN   UnaryOpNotrY   r   rP   r   r   NameIDENT_PREFIXr   LoadrB   )rM   rR   identr   r   r   rY      s    rY   c                   @   sZ   e Zd ZdZeegef ddddZeedddZe	e d	d
dZ
ed	ddZdS )MatcherAdapterzDAdapts a matcher function to a locals mapping as required by eval().Nmatcherr&   c                 C   s
   || _ d S r'   )rc   )r)   rc   r   r   r   r*      s    zMatcherAdapter.__init__)keyr&   c                 C   s   |  |ttd  S r'   )rc   r=   r^   )r)   rd   r   r   r   __getitem__   s    zMatcherAdapter.__getitem__r+   c                 C   s
   t  d S r'   NotImplementedErrorr,   r   r   r   __iter__   s    zMatcherAdapter.__iter__c                 C   s
   t  d S r'   rf   r,   r   r   r   __len__   s    zMatcherAdapter.__len__)r   r   r   r.   r   r"   rK   r*   re   r   rh   r#   ri   r   r   r   r   ra      s
   ra   c                   @   sT   e Zd ZdZdZejddddZee	d ddd	Z
ee	gef e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.
    codeN)rk   r&   c                 C   s
   || _ d S r'   rj   )r)   rk   r   r   r   r*      s    zExpression.__init__r2   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)rS   r/   compiler   )r)   r3   Zastexprrk   r   r   r   ro      s    zExpression.compilerb   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__)rl   rk   ra   )r)   rc   rR   r   r   r   evaluate   s    	zExpression.evaluate)r   r   r   r.   r    typesCodeTyper*   classmethodr"   ro   r   rK   rq   r   r   r   r   r      s   )r.   rN   dataclassesenumr>   rr   typingr   r   r   r   r   r   __all__Enumr
   	dataclassr   	Exceptionr	   r/   r^   r   rS   rP   rT   rY   r"   rK   ra   r   r   r   r   <module>   s4   

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