polymatheia.filter
The filter module implements a number of filtering classes.
All filters support the same expression language and are designed to work with the
NavigableDict. Each individual expression is structured as follows:
('operator', 'parameter'[, 'parameter', ...]). The number of parameters depends on the operator:
Equal:
('eq', param1, param2): returnsTrueif the two parameters are equalNot-equal:
('neq', param1, param2): returnsTrueif the two parameters are not equalGreater than:
('gt', param1, param2): returnsTrueif the param1 is greater than param2Greater than or equal:
('gte', param1, param2): returnsTrueif the param1 is greater than or equal to param2Less than:
('lt', param1, param2): returnsTrueif the param1 is less than param2Less than or equal:
('lte', param1, param2): returnsTrueif the param1 is less than or equal to param2Containment:
('contains', param1, param2): returnsTrueif the param2 is contained within param1Exists:
('exists', param1): returnsTrueif the param1 exists and has a value that is notNoneNot:
('not', expression): See belowAnd:
('and', expression1, expression2, ...): See belowOr:
('and', expression1, expression2, ...): See belowTrue:
('true',): always returnsTrueFalse:
('true',): always returnsFalse
In the first six expressions both param1 and param2 can be one of the following three, allowing for comparison
of a value from a NavigableDict record against a constant value, two values from the same
NavigableDict record, or two constant values:
A constant value: The comparison is performed against this value
A dotted path: The comparison is performed against the value fetched from the record using the path
A a list: The comparison is performed against the value fetched from the record using the path in list form. This is needed if either the path elements contain a full-stop or square brackets or if you wish to compare against a value at the top level of the
NavigableDictrecord.
For the operators 'not', 'and', and 'or' the expression parameter is a nested expression using any of
the given operators. The 'not' operator only supports at most a single nested expression. The 'and' and
'or' operators allow any number of nested expression parameters. This
'not','and', or'or'with no nested expressions always returnTrue'and'or'or'with a single nested expression always return the value of the nested expression'and'or'or'with more than one nested expression are evaluated lazily. That means that for'and'as soon as a nested expression isFalse,Falseis immediately returned. Likewise for'or'as soon as a nested expression isTrue, thenTrueis immediately returned.
- class polymatheia.filter.Filter(expression)
The
Filteris a callable filter forNavigableDict.- __call__(record)
Apply the expression to the
record.- Parameters:
record (
NavigableDict) – The record to apply the filter expression to.- Returns:
Whether the filter expression matches the record or not.
- Return type:
bool
- __init__(expression)
Create a new
Filter.- Parameters:
expression (
tuple) – The expression that thisFilterwill apply.
- __weakref__
list of weak references to the object (if defined)
- class polymatheia.filter.RecordsFilter(records, expression)
The
RecordsFilterprovides a records filter iteration container.It allows iterating over all
NavigableDictthat match the given filter expression. Filtering is performed using aFilter.- __init__(records, expression)
Create a new
RecordsFilter.- Parameters:
records – The source records to iterate over and filter.
expression (
tupleorFilter) – The filter expression to apply
- __iter__()
Return a new class:~polymatheia.filter.RecordsFilterIterator as the iterator.
- __weakref__
list of weak references to the object (if defined)
- class polymatheia.filter.RecordsFilterIterator(records, expression)
The
RecordsFilterIteratorprovides a records filter iterator.It allows iterating over all
NavigableDictthat match the given filter expression. Filtering is performed using aFilter.- __init__(records, expression)
Create a new
RecordsFilterIterator.- Parameters:
records – The source records to iterate over and filter.
expression (
tupleorFilter) – The filter expression to apply
- __iter__()
Return this class:~polymatheia.filter.RecordsFilterIterator as the iterator.
- __next__()
Return the next
NavigableDictthat matches the filter.- Returns:
The next record that matches the filter
- Return type:
- Raises:
StopIteration – If no more records are available
- __weakref__
list of weak references to the object (if defined)