Package ganeti :: Module qlang
[hide private]
[frames] | no frames]

Module qlang

source code

Module for a simple query language

A query filter is always a list. The first item in the list is the operator (e.g. [OP_AND, ...]), while the other items depend on the operator. For logic operators (e.g. OP_AND, OP_OR), they are subfilters whose results are combined. Unary operators take exactly one other item (e.g. a subfilter for OP_NOT and a field name for OP_TRUE). Binary operators take exactly two operands, usually a field name and a value to compare against. Filters are converted to callable functions by query._CompileFilter.

Functions [hide private]
 
MakeSimpleFilter(namefield, values)
Builds simple a filter.
source code
 
_ConvertLogicOp(op)
Creates parsing action function for logic operator.
source code
 
_ConvertRegexpValue(_, loc, toks)
Regular expression value for condition.
source code
pyparsing.ParserElement
BuildFilterParser()
Builds a parser for query filter strings.
source code
list
ParseFilter(text, parser=None)
Parses a query filter.
source code
bool
_CheckFilter(text)
CHecks if a string could be a filter.
source code
bool
_CheckGlobbing(text)
Checks if a string could be a globbing pattern.
source code
 
_MakeFilterPart(namefield, text, isnumeric=False)
Generates filter for one argument.
source code
list
MakeFilter(args, force_filter, namefield=None, isnumeric=False)
Try to make a filter from arguments to a command.
source code
Variables [hide private]
  OP_OR = constants.QLANG_OP_OR
  OP_AND = constants.QLANG_OP_AND
  OP_NOT = constants.QLANG_OP_NOT
  OP_TRUE = constants.QLANG_OP_TRUE
  OP_EQUAL = constants.QLANG_OP_EQUAL
  OP_EQUAL_LEGACY = constants.QLANG_OP_EQUAL_LEGACY
  OP_NOT_EQUAL = constants.QLANG_OP_NOT_EQUAL
  OP_LT = constants.QLANG_OP_LT
  OP_LE = constants.QLANG_OP_LE
  OP_GT = constants.QLANG_OP_GT
  OP_GE = constants.QLANG_OP_GE
  OP_REGEXP = constants.QLANG_OP_REGEXP
  OP_CONTAINS = constants.QLANG_OP_CONTAINS
  FILTER_DETECTION_CHARS = constants.QLANG_FILTER_DETECTION_CHARS
  GLOB_DETECTION_CHARS = constants.QLANG_GLOB_DETECTION_CHARS
  _KNOWN_REGEXP_DELIM = "/#^|"
  _KNOWN_REGEXP_FLAGS = frozenset("si")

Imports: re, logging, pyp, constants, errors, utils, compat


Function Details [hide private]

MakeSimpleFilter(namefield, values)

source code 

Builds simple a filter.

Parameters:
  • namefield - Name of field containing item name
  • values - List of names

_ConvertLogicOp(op)

source code 

Creates parsing action function for logic operator.

Parameters:
  • op (string) - Operator for data structure, e.g. OP_AND

ParseFilter(text, parser=None)

source code 

Parses a query filter.

Parameters:
  • text (string) - Query filter
  • parser (pyparsing.ParserElement) - Pyparsing object
Returns: list

MakeFilter(args, force_filter, namefield=None, isnumeric=False)

source code 

Try to make a filter from arguments to a command.

If the name could be a filter it is parsed as such. If it's just a globbing pattern, e.g. "*.site", such a filter is constructed. As a last resort the names are treated just as a plain name filter.

Parameters:
  • args (list of string) - Arguments to command
  • force_filter (bool) - Whether to force treatment as a full-fledged filter
  • namefield (string) - Name of field to use for simple filters (use None for a default of "name")
  • isnumeric (bool) - Whether the namefield type is numeric, as opposed to the default string type; this influences how the filter is built
Returns: list
Query filter