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.
|
|
|
|
|
_ConvertRegexpValue(_,
loc,
toks)
Regular expression value for condition. |
source code
|
|
pyparsing.ParserElement
|
BuildFilterParser()
Builds a parser for query filter strings. |
source code
|
|
list
|
|
bool
|
_IsHostname(text)
Checks if a string could be a hostname. |
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)
Generates filter for one argument. |
source code
|
|
list
|
|
|
OP_OR = "|"
|
|
OP_AND = "&"
|
|
OP_NOT = "!"
|
|
OP_TRUE = "?"
|
|
OP_EQUAL = "="
|
|
OP_NOT_EQUAL = "!="
|
|
OP_REGEXP = "=~"
|
|
OP_CONTAINS = "=[]"
|
|
FILTER_DETECTION_CHARS = frozenset("()=/!~'\"\\"+ string.white...
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,
netutils,
utils,
compat
Builds simple a filter.
- Parameters:
namefield - Name of field containing item name
values - List of names
|
Creates parsing action function for logic operator.
- Parameters:
op (string) - Operator for data structure, e.g. OP_AND
|
Parses a query filter.
- Parameters:
text (string) - Query filter
parser (pyparsing.ParserElement) - Pyparsing object
- Returns: list
|
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
- Returns: list
- Query filter
|
FILTER_DETECTION_CHARS
Characters used for detecting user-written filters (see _CheckFilter)
- Value:
frozenset("()=/!~'\"\\"+ string.whitespace)
|
|