Package ganeti :: Module query :: Class _FilterCompilerHelper
[hide private]
[frames] | no frames]

Class _FilterCompilerHelper

source code

Converts a query filter to a callable usable for filtering.

Instance Methods [hide private]
 
__init__(self, fields)
Initializes this class.
source code
callable
__call__(self, hints, filter_)
Converts a query filter into a callable function.
source code
 
_Compile(self, filter_, level)
Inner function for converting filters.
source code
 
_LookupField(self, name)
Returns a field definition by name.
source code
 
_HandleLogicOp(self, hints_fn, level, op, op_fn, operands)
Handles logic operators.
source code
 
_HandleUnaryOp(self, hints_fn, level, op, op_fn, operands)
Handles unary operators.
source code
 
_HandleBinaryOp(self, hints_fn, level, op, op_data, operands)
Handles binary operators.
source code
Class Variables [hide private]
  _LEVELS_MAX = 10
How deep filters can be nested
  _EQUALITY_CHECKS = [(QFF_HOSTNAME, lambda lhs, rhs: utils.Matc...
Known operators
  _OPS = {qlang.OP_OR:(_OPTYPE_LOGIC, compat.any), qlang.OP_AND:...
Method Details [hide private]

__init__(self, fields)
(Constructor)

source code 

Initializes this class.

Parameters:

__call__(self, hints, filter_)
(Call operator)

source code 

Converts a query filter into a callable function.

Parameters:
  • hints (_FilterHints or None) - Callbacks doing analysis on filter
  • filter_ (list) - Filter structure
Returns: callable
Function receiving context and item as parameters, returning boolean as to whether item matches filter

_Compile(self, filter_, level)

source code 

Inner function for converting filters.

Calls the correct handler functions for the top-level operator. This function is called recursively (e.g. for logic operators).

_HandleLogicOp(self, hints_fn, level, op, op_fn, operands)

source code 

Handles logic operators.

Parameters:
  • hints_fn (callable) - Callback doing some analysis on the filter
  • level (integer) - Current depth
  • op (string) - Operator
  • op_fn (callable) - Function implementing operator
  • operands (list) - List of operands

_HandleUnaryOp(self, hints_fn, level, op, op_fn, operands)

source code 

Handles unary operators.

Parameters:
  • hints_fn (callable) - Callback doing some analysis on the filter
  • level (integer) - Current depth
  • op (string) - Operator
  • op_fn (callable) - Function implementing operator
  • operands (list) - List of operands

_HandleBinaryOp(self, hints_fn, level, op, op_data, operands)

source code 

Handles binary operators.

Parameters:
  • hints_fn (callable) - Callback doing some analysis on the filter
  • level (integer) - Current depth
  • op (string) - Operator
  • op_data - Functions implementing operators
  • operands (list) - List of operands

Class Variable Details [hide private]

_EQUALITY_CHECKS

Known operators

Operator as key (qlang.OP_*), value a tuple of operator group (_OPTYPE_*) and a group-specific value:

  • _OPTYPE_LOGIC: Callable taking any number of arguments; used by _HandleLogicOp
  • _OPTYPE_UNARY: Always None; details handled by _HandleUnaryOp
  • _OPTYPE_BINARY: Callable taking exactly two parameters, the left- and right-hand side of the operator, used by _HandleBinaryOp
Value:
[(QFF_HOSTNAME, lambda lhs, rhs: utils.MatchNameComponent(rhs, [lhs], \
case_sensitive= False), None), (None, operator.eq, None),]

_OPS

Value:
{qlang.OP_OR:(_OPTYPE_LOGIC, compat.any), qlang.OP_AND:(_OPTYPE_LOGIC,\
 compat.all), qlang.OP_NOT:(_OPTYPE_UNARY, None), qlang.OP_TRUE:(_OPTY\
PE_UNARY, None), qlang.OP_EQUAL:(_OPTYPE_BINARY, _EQUALITY_CHECKS), ql\
ang.OP_NOT_EQUAL:(_OPTYPE_BINARY, [(flags, compat.partial(_WrapNot, fn\
), valprepfn) for(flags, fn, valprepfn) in _EQUALITY_CHECKS]), qlang.O\
P_REGEXP:(_OPTYPE_BINARY, [(None, lambda lhs, rhs: rhs.search(lhs), _P\
repareRegex),]), qlang.OP_CONTAINS:(_OPTYPE_BINARY, [(None, operator.c\
ontains, None),]),}