link.utils package¶
Submodules¶
link.utils.filter module¶
-
class
link.utils.filter.
Filter
(rule, *args, **kwargs)[source]¶ Bases:
object
Apply MongoDB filter rule on dictionary.
-
handle_all_field
(key, rule, obj)[source]¶ Handle
$all
operator.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
$and
operator.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
$exists
operator.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
$regex
operator.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
$in
operator.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
$nor
operator.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:
object
Apply MongoDB update spec on dictionary.
-
addToSet
(rule, obj)[source]¶ Handle
$addToSet
operator.Parameters: - rule (dict) – sub-spec
- obj (dict) – dictionary to apply sub-rule on
-
bit
(rule, obj)[source]¶ Handle
$bit
operator.Parameters: - rule (dict) – sub-spec
- obj (dict) – dictionary to apply sub-rule on
-
currentDate
(rule, obj)[source]¶ Handle
$currentDate
operator.Parameters: - rule (dict) – sub-spec
- obj (dict) – dictionary to apply sub-rule on
-
inc
(rule, obj)[source]¶ Handle
$inc
operator.Parameters: - rule (dict) – sub-spec
- obj (dict) – dictionary to apply sub-rule on
-
max
(rule, obj)[source]¶ Handle
$max
operator.Parameters: - rule (dict) – sub-spec
- obj (dict) – dictionary to apply sub-rule on
-
min
(rule, obj)[source]¶ Handle
$min
operator.Parameters: - rule (dict) – sub-spec
- obj (dict) – dictionary to apply sub-rule on
-
mul
(rule, obj)[source]¶ Handle
$mul
operator.Parameters: - rule (dict) – sub-spec
- obj (dict) – dictionary to apply sub-rule on
-
pop
(rule, obj)[source]¶ Handle
$pop
operator.Parameters: - rule (dict) – sub-spec
- obj (dict) – dictionary to apply sub-rule on
-
pull
(rule, obj)[source]¶ Handle
$pull
operator.Parameters: - rule (dict) – sub-spec
- obj (dict) – dictionary to apply sub-rule on
-
pullAll
(rule, obj)[source]¶ Handle
$pullAll
operator.Parameters: - rule (dict) – sub-spec
- obj (dict) – dictionary to apply sub-rule on
-
push
(rule, obj)[source]¶ Handle
$push
operator.Parameters: - rule (dict) – sub-spec
- obj (dict) – dictionary to apply sub-rule on
-
rename
(rule, obj)[source]¶ Handle
$rename
operator.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.Logger
Configurable 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