
                             d Z ddlmZ ddlmZ ddlmZ  G d de      Z G d de      Z G d	 d
e      Z G d de      Z	 G d de      Z
y)z8Cloud resource filter expression referenced key backend.    )absolute_import)division)unicode_literalsc                       e Zd ZdZddZd Zd Zd Zd Zd Z	d	 Z
dd
ZddZddZddZddZddZddZddZddZd Zy)Backendau  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                     g | _         y N)keys)selfsupported_keys     6lib/googlecloudsdk/core/resource/resource_keys_expr.py__init__zBackend.__init__(   s	    DI    c                      y r	    r   s    r   ExprTRUEzBackend.ExprTRUE-       r   c                     t        | ||      S r	   _ExprLogicalr   leftrights      r   ExprANDzBackend.ExprAND0       dE**r   c                     t        | ||      S r	   r   r   s      r   ExprORzBackend.ExprOR3   r   r   c                     t        | |      S r	   )_ExprNOT)r   exprs     r   ExprNOTzBackend.ExprNOT6   s    D$r   c                      y r	   r   )r   unused_funcunused_argss      r   
ExprGlobalzBackend.ExprGlobal9   r   r   c                      y r	   r   )r   unused_values     r   ExprOperandzBackend.ExprOperand<   r   r   c                      t        | ||||      S r	   _ExprOperatorr   keyoperand	transformargss        r   ExprLTzBackend.ExprLT?       sGY==r   c                      t        | ||||      S r	   r+   r-   s        r   ExprLEzBackend.ExprLEB   r3   r   c                      t        | ||||      S r	   r+   r-   s        r   ExprHASzBackend.ExprHASE   r3   r   c                      t        | ||||      S r	   r+   r-   s        r   ExprEQzBackend.ExprEQH   r3   r   c                      t        | ||||      S r	   r+   r-   s        r   ExprNEzBackend.ExprNEK   r3   r   c                      t        | ||||      S r	   r+   r-   s        r   ExprGEzBackend.ExprGEN   r3   r   c                      t        | ||||      S r	   r+   r-   s        r   ExprGTzBackend.ExprGTQ   r3   r   c                      t        | ||||      S r	   r+   r-   s        r   ExprREzBackend.ExprRET   r3   r   c                      t        | ||||      S r	   r+   r-   s        r   	ExprNotREzBackend.ExprNotREW   r3   r   c                      y)NFr   r   s    r   
IsRewriterzBackend.IsRewriterZ   s    r   r	   )NN)__name__
__module____qualname____doc__r   r   r   r   r"   r&   r)   r2   r5   r7   r9   r;   r=   r?   rA   rC   rE   r   r   r   r   r      s\    
++ >>>>>>>>>r   r   c                       e Zd ZdZd Zd Zy)_ExprzExpression base class.c                     || _         y r	   )backend)r   rM   s     r   r   z_Expr.__init__d   s	    DLr   c                 .    | j                   j                  S )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.
    )rM   r
   )r   
unused_objs     r   Evaluatez_Expr.Evaluateg   s     <<r   N)rF   rG   rH   rI   r   rP   r   r   r   rK   rK   a   s    	r   rK   c                   (     e Zd ZdZ fdZd Z xZS )r   ziBase logical operator node.

  Attributes:
    left: Left Expr operand.
    right: Right Expr operand.
  c                 H    t         t        |   |       || _        || _        y r	   )superr   r   _left_right)r   rM   r   r   	__class__s       r   r   z_ExprLogical.__init__{   s     	,&w/DJDKr   c                     | j                   j                  |       | j                  j                  |       | j                  j                  S r	   )rT   rP   rU   rM   r
   r   objs     r   rP   z_ExprLogical.Evaluate   s6    JJKK<<r   rF   rG   rH   rI   r   rP   __classcell__rV   s   @r   r   r   s   s    
r   r   c                   (     e Zd ZdZ fdZd Z xZS )r    z	NOT node.c                 :    t         t        |   |       || _        y r	   )rS   r    r   _expr)r   rM   r!   rV   s      r   r   z_ExprNOT.__init__   s    	(D"7+DJr   c                 d    | j                   j                  |       | j                  j                  S r	   )r_   rP   rM   r
   rX   s     r   rP   z_ExprNOT.Evaluate   s$    JJ<<r   rZ   r\   s   @r   r    r       s    r   r    c                   "     e Zd ZdZ fdZ xZS )r,   z(Base term (<key operator operand>) node.c                     t         t        |   |       || j                  j                  vr&| j                  j                  j                  |       y y r	   )rS   r,   r   rM   r
   append)r   rM   r.   unused_operandunused_transformr%   rV   s         r   r   z_ExprOperator.__init__   sA    	-'0
$,,###
lls# $r   )rF   rG   rH   rI   r   r[   r\   s   @r   r,   r,      s    0$ $r   r,   N)rI   
__future__r   r   r   objectr   rK   r   r    r,   r   r   r   <module>rh      sT     ? '  'Cf CRF $5 &	u 	$E $r   