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 = "|"
  OP_AND = "&"
  OP_NOT = "!"
  OP_TRUE = "?"
  OP_EQUAL = "="
  OP_NOT_EQUAL = "!="
  OP_LT = "<"
  OP_LE = "<="
  OP_GT = ">"
  OP_GE = ">="
  OP_REGEXP = "=~"
  OP_CONTAINS = "=[]"
  FILTER_DETECTION_CHARS = frozenset("()=/!~'\"\\<>"+ string.whi...
Characters used for detecting user-written filters (see _CheckFilter)
  GLOB_DETECTION_CHARS = frozenset("*?")
Characters used to detect globbing filters (see _CheckGlobbing)
  _KNOWN_REGEXP_DELIM = "/#^|"
  _KNOWN_REGEXP_FLAGS = frozenset("si")

Imports: re, string, logging, pyp, 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

Variables Details [hide private]

FILTER_DETECTION_CHARS

Characters used for detecting user-written filters (see _CheckFilter)

Value:
frozenset("()=/!~'\"\\<>"+ string.whitespace)