link.utils package¶
Submodules¶
link.utils.filter module¶
-
class
link.utils.filter.Filter(rule, *args, **kwargs)[source]¶ Bases:
objectApply MongoDB filter rule on dictionary.
-
handle_all_field(key, rule, obj)[source]¶ Handle
$alloperator.Parameters: - key (str) – key to check in dictionary
- rule (dict) – MongoDB sub-filter
- obj (dict) – dictionary to check
Returns: True if field match all values
Return type: boolean
-
handle_and(key, rule, obj)[source]¶ Handle
$andoperator.Parameters: - key (str) – key to check in dictionary (unused)
- rule (dict) – MongoDB sub-filter
- obj (dict) – dictionary to check
Returns: True if dictionary match all sub-filters
Return type: boolean
-
handle_field(key, rule, obj)[source]¶ Handle filter on field.
Parameters: - key (str) – key to check in dictionary
- rule (dict) – MongoDB sub-filter
- obj (dict) – dictionary to check
Returns: True if dictionary match
Return type: boolean
-
handle_field_cond(key, rule, obj, cond)[source]¶ Handle comparison operators.
Parameters: - key (str) – key to check in dictionary
- rule (dict) – MongoDB sub-filter
- obj (dict) – dictionary to check
- cond (callable) – comparison operator
Returns: True if field match
Return type: boolean
-
handle_field_exists(key, rule, obj)[source]¶ Handle
$existsoperator.Parameters: - key (str) – key to check in dictionary
- rule (dict) – MongoDB sub-filter
- obj (dict) – dictionary to check
Returns: True if field is in dictionary
Return type: boolean
-
handle_field_regex(key, pattern, obj, opts=None)[source]¶ Handle
$regexoperator.Parameters: - key (str) – key to check in dictionary
- rule (dict) – MongoDB sub-filter
- obj (dict) – dictionary to check
Returns: True if field match regex
Return type: boolean
-
handle_field_rule(key, rule, obj)[source]¶ Handle other operators.
Parameters: - key (str) – key to check in dictionary
- rule (dict) – MongoDB sub-filter
- obj (dict) – dictionary to check
Returns: True if field match
Return type: boolean
-
handle_in_field(key, rule, obj)[source]¶ Handle
$inoperator.Parameters: - key (str) – key to check in dictionary
- rule (dict) – MongoDB sub-filter
- obj (dict) – dictionary to check
Returns: True if field match at least one value
Return type: boolean
-
handle_nor(key, rule, obj)[source]¶ Handle
$noroperator.Parameters: - key (str) – key to check in dictionary (unused)
- rule (dict) – MongoDB sub-filter
- obj (dict) – dictionary to check
Returns: True if dictionary doesn’t match any sub-filters
Return type: boolean
-
-
class
link.utils.filter.Mangle(rule, *args, **kwargs)[source]¶ Bases:
objectApply MongoDB update spec on dictionary.
-
addToSet(rule, obj)[source]¶ Handle
$addToSetoperator.Parameters: - rule (dict) – sub-spec
- obj (dict) – dictionary to apply sub-rule on
-
bit(rule, obj)[source]¶ Handle
$bitoperator.Parameters: - rule (dict) – sub-spec
- obj (dict) – dictionary to apply sub-rule on
-
currentDate(rule, obj)[source]¶ Handle
$currentDateoperator.Parameters: - rule (dict) – sub-spec
- obj (dict) – dictionary to apply sub-rule on
-
inc(rule, obj)[source]¶ Handle
$incoperator.Parameters: - rule (dict) – sub-spec
- obj (dict) – dictionary to apply sub-rule on
-
max(rule, obj)[source]¶ Handle
$maxoperator.Parameters: - rule (dict) – sub-spec
- obj (dict) – dictionary to apply sub-rule on
-
min(rule, obj)[source]¶ Handle
$minoperator.Parameters: - rule (dict) – sub-spec
- obj (dict) – dictionary to apply sub-rule on
-
mul(rule, obj)[source]¶ Handle
$muloperator.Parameters: - rule (dict) – sub-spec
- obj (dict) – dictionary to apply sub-rule on
-
pop(rule, obj)[source]¶ Handle
$popoperator.Parameters: - rule (dict) – sub-spec
- obj (dict) – dictionary to apply sub-rule on
-
pull(rule, obj)[source]¶ Handle
$pulloperator.Parameters: - rule (dict) – sub-spec
- obj (dict) – dictionary to apply sub-rule on
-
pullAll(rule, obj)[source]¶ Handle
$pullAlloperator.Parameters: - rule (dict) – sub-spec
- obj (dict) – dictionary to apply sub-rule on
-
push(rule, obj)[source]¶ Handle
$pushoperator.Parameters: - rule (dict) – sub-spec
- obj (dict) – dictionary to apply sub-rule on
-
rename(rule, obj)[source]¶ Handle
$renameoperator.Parameters: - rule (dict) – sub-spec
- obj (dict) – dictionary to apply sub-rule on
-
-
link.utils.filter.del_field(key, obj)[source]¶ Remove field from dictionary.
Parameters: - key (str) – path to field in dictionary
- obj (dict) – dictionary used for search
link.utils.log module¶
-
class
link.utils.log.ConfigurableLogger(name)[source]¶ Bases:
logging.LoggerConfigurable logger.
-
log_filter¶
-
log_format¶
-
log_level¶
-
link.utils.grammar module¶
-
link.utils.grammar.codegenerator(modname, prefix, grammar)[source]¶ Parse grammar model and generate Python code allowing to parse it.
Example:
with open('grammar.bnf') as f: module = codegenerator('mydsl', 'MyDSL', f.read()) assert module.__name__ == 'mydsl' parser = module.MyDSLParser()
Parameters: - modname (str) – Name of the generated Python module
- prefix (str) – Prefix used to name the parser
- grammar (str) – Grammar describing the language to parse
Returns: Generated Python module
Return type: module