HEX
Server: Apache/2.4.65 (Ubuntu)
System: Linux ielts-store-v2 6.8.0-1036-gcp #38~22.04.1-Ubuntu SMP Thu Aug 14 01:19:18 UTC 2025 x86_64
User: root (0)
PHP: 7.2.34-54+ubuntu20.04.1+deb.sury.org+1
Disabled: pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,
Upload Files
File: //snap/google-cloud-cli/396/lib/googlecloudsdk/core/resource/resource_keys_expr.py
# -*- coding: utf-8 -*- #
# Copyright 2016 Google LLC. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#    http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""Cloud resource filter expression referenced key backend."""


from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals


class Backend(object):
  """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.
  """

  def __init__(self, supported_key=None):  # pylint: disable=unused-argument
    self.keys = []

  # The remaining methods return an initialized class object.

  def ExprTRUE(self):
    return None

  def ExprAND(self, left, right):
    return _ExprLogical(self, left, right)

  def ExprOR(self, left, right):
    return _ExprLogical(self, left, right)

  def ExprNOT(self, expr):
    return _ExprNOT(self, expr)

  def ExprGlobal(self, unused_func, unused_args):
    return None

  def ExprOperand(self, unused_value):
    return None

  def ExprLT(self, key, operand, transform=None, args=None):
    return _ExprOperator(self, key, operand, transform, args)

  def ExprLE(self, key, operand, transform=None, args=None):
    return _ExprOperator(self, key, operand, transform, args)

  def ExprHAS(self, key, operand, transform=None, args=None):
    return _ExprOperator(self, key, operand, transform, args)

  def ExprEQ(self, key, operand, transform=None, args=None):
    return _ExprOperator(self, key, operand, transform, args)

  def ExprNE(self, key, operand, transform=None, args=None):
    return _ExprOperator(self, key, operand, transform, args)

  def ExprGE(self, key, operand, transform=None, args=None):
    return _ExprOperator(self, key, operand, transform, args)

  def ExprGT(self, key, operand, transform=None, args=None):
    return _ExprOperator(self, key, operand, transform, args)

  def ExprRE(self, key, operand, transform=None, args=None):
    return _ExprOperator(self, key, operand, transform, args)

  def ExprNotRE(self, key, operand, transform=None, args=None):
    return _ExprOperator(self, key, operand, transform, args)

  def IsRewriter(self):
    return False


# _Expr* class instantiations are done by the Backend.Expr* methods.


class _Expr(object):
  """Expression base class."""

  def __init__(self, backend):
    self.backend = backend

  def Evaluate(self, unused_obj):
    """Returns 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.
    """
    return self.backend.keys


class _ExprLogical(_Expr):
  """Base logical operator node.

  Attributes:
    left: Left Expr operand.
    right: Right Expr operand.
  """

  def __init__(self, backend, left, right):
    super(_ExprLogical, self).__init__(backend)
    self._left = left
    self._right = right

  def Evaluate(self, obj):
    self._left.Evaluate(obj)
    self._right.Evaluate(obj)
    return self.backend.keys


class _ExprNOT(_Expr):
  """NOT node."""

  def __init__(self, backend, expr):
    super(_ExprNOT, self).__init__(backend)
    self._expr = expr

  def Evaluate(self, obj):
    self._expr.Evaluate(obj)
    return self.backend.keys


class _ExprOperator(_Expr):
  """Base term (<key operator operand>) node."""

  def __init__(self, backend, key, unused_operand, unused_transform,
               unused_args):
    super(_ExprOperator, self).__init__(backend)
    if key not in self.backend.keys:
      self.backend.keys.append(key)