o
                         @   s|   d Z ddlmZ ddlmZ ddlmZ G dd deZG dd deZG d	d
 d
eZG dd deZ	G dd deZ
dS )z8Cloud resource filter expression referenced key backend.    )absolute_import)division)unicode_literalsc                   @   s   e Zd ZdZd%ddZdd Zdd Zd	d
 Zdd Zdd Z	dd Z
d&ddZd&ddZd&ddZd&ddZd&ddZd&ddZd&ddZd&dd Zd&d!d"Zd#d$ ZdS )'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                 C   s
   g | _ d S N)keys)selfsupported_key r
   L/tmp/google-cloud-sdk/lib/googlecloudsdk/core/resource/resource_keys_expr.py__init__(      
zBackend.__init__c                 C      d S r   r
   r   r
   r
   r   ExprTRUE-      zBackend.ExprTRUEc                 C      t | ||S r   _ExprLogicalr   leftrightr
   r
   r   ExprAND0      zBackend.ExprANDc                 C   r   r   r   r   r
   r
   r   ExprOR3   r   zBackend.ExprORc                 C   s
   t | |S r   )_ExprNOT)r   exprr
   r
   r   ExprNOT6   r   zBackend.ExprNOTc                 C   r   r   r
   )r   unused_funcunused_argsr
   r
   r   
ExprGlobal9   r   zBackend.ExprGlobalc                 C   r   r   r
   )r   unused_valuer
   r
   r   ExprOperand<   r   zBackend.ExprOperandc                 C      t | ||||S r   _ExprOperatorr   keyoperand	transformargsr
   r
   r   ExprLT?      zBackend.ExprLTc                 C   r#   r   r$   r&   r
   r
   r   ExprLEB   r,   zBackend.ExprLEc                 C   r#   r   r$   r&   r
   r
   r   ExprHASE   r,   zBackend.ExprHASc                 C   r#   r   r$   r&   r
   r
   r   ExprEQH   r,   zBackend.ExprEQc                 C   r#   r   r$   r&   r
   r
   r   ExprNEK   r,   zBackend.ExprNEc                 C   r#   r   r$   r&   r
   r
   r   ExprGEN   r,   zBackend.ExprGEc                 C   r#   r   r$   r&   r
   r
   r   ExprGTQ   r,   zBackend.ExprGTc                 C   r#   r   r$   r&   r
   r
   r   ExprRET   r,   zBackend.ExprREc                 C   r#   r   r$   r&   r
   r
   r   	ExprNotREW   r,   zBackend.ExprNotREc                 C   s   dS )NFr
   r   r
   r
   r   
IsRewriterZ   r   zBackend.IsRewriterr   )NN)__name__
__module____qualname____doc__r   r   r   r   r   r    r"   r+   r-   r.   r/   r0   r1   r2   r3   r4   r5   r
   r
   r
   r   r      s&    









r   c                   @   s    e Zd ZdZdd Zdd ZdS )_ExprzExpression base class.c                 C   s
   || _ d S r   )backend)r   r;   r
   r
   r   r   d   r   z_Expr.__init__c                 C   s   | 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.
    )r;   r   )r   
unused_objr
   r
   r   Evaluateg   s   	z_Expr.EvaluateN)r6   r7   r8   r9   r   r=   r
   r
   r
   r   r:   a   s    r:   c                       (   e Zd ZdZ fddZdd Z  ZS )r   ziBase logical operator node.

  Attributes:
    left: Left Expr operand.
    right: Right Expr operand.
  c                    s    t t| | || _|| _d S r   )superr   r   _left_right)r   r;   r   r   	__class__r
   r   r   {   s   
z_ExprLogical.__init__c                 C   s    | j | | j| | jjS r   )r@   r=   rA   r;   r   r   objr
   r
   r   r=      s   z_ExprLogical.Evaluater6   r7   r8   r9   r   r=   __classcell__r
   r
   rB   r   r   s   s    r   c                       r>   )r   z	NOT node.c                    s   t t| | || _d S r   )r?   r   r   _expr)r   r;   r   rB   r
   r   r      s   
z_ExprNOT.__init__c                 C   s   | j | | jjS r   )rH   r=   r;   r   rD   r
   r
   r   r=      s   z_ExprNOT.EvaluaterF   r
   r
   rB   r   r      s    r   c                       s    e Zd ZdZ fddZ  ZS )r%   z(Base term (<key operator operand>) node.c                    s2   t t| | || jjvr| jj| d S d S r   )r?   r%   r   r;   r   append)r   r;   r'   unused_operandunused_transformr   rB   r
   r   r      s   z_ExprOperator.__init__)r6   r7   r8   r9   r   rG   r
   r
   rB   r   r%      s    r%   N)r9   
__future__r   r   r   objectr   r:   r   r   r%   r
   r
   r
   r   <module>   s   I