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, qfilter)
Converts a query filter into a callable function.
source code
 
_Compile(self, qfilter, 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

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __sizeof__, __str__, __subclasshook__

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:...
Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self, fields)
(Constructor)

source code 

Initializes this class.

Parameters:
Overrides: object.__init__

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

source code 

Converts a query filter into a callable function.

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

_Compile(self, qfilter, 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), (QFF_SPLIT_TIMESTAMP, _MakeSplitTimesta\
mpComparison(operator.eq), _PrepareSplitTimestamp), (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_EQUAL_LEGACY:(_OPTYPE_BINARY, _EQUALITY_CHECKS), qlang.OP_NOT_E\
QUAL:(_OPTYPE_BINARY, [(flags, compat.partial(_WrapNot, fn), valprepfn\
) for(flags, fn, valprepfn) in _EQUALITY_CHECKS]), qlang.OP_LT:(_OPTYP\
E_BINARY, _MakeComparisonChecks(operator.lt)), qlang.OP_LE:(_OPTYPE_BI\
NARY, _MakeComparisonChecks(operator.le)), qlang.OP_GT:(_OPTYPE_BINARY\
...