
                             S r SSKJr  SSKJr  SSKJr   " S S\5      r " S S\5      r " S	 S
\5      r " S S\5      r	 " S S\5      r
g)z8Cloud resource filter expression referenced key backend.    )absolute_import)division)unicode_literalsc                       \ rS rSrSrSS jrS rS rS rS r	S	 r
S
 rSS jrSS jrSS jrSS jrSS jrSS jrSS jrSS jrSS jrS rSrg)Backend   aa  Cloud resource filter expression referenced key backend.

This is a backend for resource_filter.Parser(). The generated "evaluator" is a
parsed resource expression tree with branching factor 2 for binary operator
nodes, 1 for NOT and function nodes, and 0 for TRUE nodes. Evaluation starts
with expression_tree_root.Evaluate(obj) which recursively evaluates child
nodes. The Evaluate() method generates the list of parsed keys referenced by
the expression.

For a complete backend expression evaluator see core.resource.resource_expr.

Attributes:
  keys: The set of parsed keys referenced by the expression.
Nc                     / U l         g Nkeys)selfsupported_keys     6lib/googlecloudsdk/core/resource/resource_keys_expr.py__init__Backend.__init__(   s	    DI    c                     g r
    r   s    r   ExprTRUEBackend.ExprTRUE-       r   c                     [        XU5      $ r
   _ExprLogicalr   leftrights      r   ExprANDBackend.ExprAND0       E**r   c                     [        XU5      $ r
   r   r   s      r   ExprORBackend.ExprOR3   r!   r   c                     [        X5      $ r
   )_ExprNOT)r   exprs     r   ExprNOTBackend.ExprNOT6   s    Dr   c                     g r
   r   )r   unused_funcunused_argss      r   
ExprGlobalBackend.ExprGlobal9   r   r   c                     g r
   r   )r   unused_values     r   ExprOperandBackend.ExprOperand<   r   r   c                     [        XX#U5      $ r
   _ExprOperatorr   keyoperand	transformargss        r   ExprLTBackend.ExprLT?       G==r   c                     [        XX#U5      $ r
   r4   r6   s        r   ExprLEBackend.ExprLEB   r=   r   c                     [        XX#U5      $ r
   r4   r6   s        r   ExprHASBackend.ExprHASE   r=   r   c                     [        XX#U5      $ r
   r4   r6   s        r   ExprEQBackend.ExprEQH   r=   r   c                     [        XX#U5      $ r
   r4   r6   s        r   ExprNEBackend.ExprNEK   r=   r   c                     [        XX#U5      $ r
   r4   r6   s        r   ExprGEBackend.ExprGEN   r=   r   c                     [        XX#U5      $ r
   r4   r6   s        r   ExprGTBackend.ExprGTQ   r=   r   c                     [        XX#U5      $ r
   r4   r6   s        r   ExprREBackend.ExprRET   r=   r   c                     [        XX#U5      $ r
   r4   r6   s        r   	ExprNotREBackend.ExprNotREW   r=   r   c                     g)NFr   r   s    r   
IsRewriterBackend.IsRewriterZ   s    r   r   r
   )NN)__name__
__module____qualname____firstlineno____doc__r   r   r   r#   r(   r-   r1   r;   r?   rB   rE   rH   rK   rN   rQ   rT   rW   __static_attributes__r   r   r   r   r      s\    
++ >>>>>>>>>r   r   c                   $    \ rS rSrSrS rS rSrg)_Expra   zExpression base class.c                     Xl         g r
   backend)r   rd   s     r   r   _Expr.__init__d   s    Lr   c                 .    U R                   R                  $ )zReturns the set of parsed keys referenced by the exptression.

Args:
 unused_ obj: The current resource object.

Returns:
  Returns the set of parsed keys referenced by the exptression.
)rd   r   )r   
unused_objs     r   Evaluate_Expr.Evaluateg   s     <<r   rc   N)rY   rZ   r[   r\   r]   r   rh   r^   r   r   r   r`   r`   a   s    	r   r`   c                   2   ^  \ rS rSrSrU 4S jrS rSrU =r$ )r   s   zaBase logical operator node.

Attributes:
  left: Left Expr operand.
  right: Right Expr operand.
c                 D   > [         [        U ]  U5        X l        X0l        g r
   )superr   r   _left_right)r   rd   r   r   	__class__s       r   r   _ExprLogical.__init__{   s    	,&w/JKr   c                     U R                   R                  U5        U R                  R                  U5        U R                  R                  $ r
   )rn   rh   ro   rd   r   r   objs     r   rh   _ExprLogical.Evaluate   s6    JJKK<<r   )rn   ro   	rY   rZ   r[   r\   r]   r   rh   r^   __classcell__rp   s   @r   r   r   s   s    
 r   r   c                   2   ^  \ rS rSrSrU 4S jrS rSrU =r$ )r&      z	NOT node.c                 8   > [         [        U ]  U5        X l        g r
   )rm   r&   r   _expr)r   rd   r'   rp   s      r   r   _ExprNOT.__init__   s    	(D"7+Jr   c                 d    U R                   R                  U5        U R                  R                  $ r
   )r|   rh   rd   r   rs   s     r   rh   _ExprNOT.Evaluate   s$    JJ<<r   )r|   rv   rx   s   @r   r&   r&      s     r   r&   c                   ,   ^  \ rS rSrSrU 4S jrSrU =r$ )r5      z(Base term (<key operator operand>) node.c                    > [         [        U ]  U5        X R                  R                  ;  a&  U R                  R                  R                  U5        g g r
   )rm   r5   r   rd   r   append)r   rd   r7   unused_operandunused_transformr,   rp   s         r   r   _ExprOperator.__init__   s?    	-'0
,,###
lls# $r   r   )rY   rZ   r[   r\   r]   r   r^   rw   rx   s   @r   r5   r5      s    0$ $r   r5   N)r]   
__future__r   r   r   objectr   r`   r   r&   r5   r   r   r   <module>r      sT     ? '  'Cf CRF $5 &	u 	$E $r   