polymatheia.transform
The transform module implements a number of transform classes.
All transform classes use the following transform expression language and are designed to work with
NavigableDict. Each transform is structured as follows:
('operator', 'parameter'[, 'parameter', ...]). The number of parameters depends on the operator:
Static:
('static', target, value): The staticvalueis stored at the location specified by the dotted pathtarget.Copy:
('copy', target, source): The value specified by the dotted pathsourceis stored at the location specified by the dotted pathtarget.Fill:
('fill', target, value): If the value specified by the dotted pathtargetisNone, then this is replaced by thevalue, otherwise it is left untouched.Split:
('split', target, splitter, source): The value specified by the dotted path ``sourceis split and stored at the location specified by the dotted pathtarget. If the value is alist, then the list is split into its elements. If the value is astr, then it is split usingsplitter`. Because this will produce more than one value in the transformation result, the ``targetcan contain the string{}, which is replaced with the index of each split value (starting at 1).Combine:
('combine', target, source1, ...): The values specified by the dotted pathssource1(and optionallysource2,source3,…) are combined into a list and stored at the location specified by the dotted pathtarget.Join:
('join', target, joiner, source1, ...): The values specified by the dotted pathssource1(and optionallysource2,source3,…) are joined by thejoinerand the result stored at the location specified by the dotted pathtarget. If only onesourceis specified, this is treated as alistand the values of thelistjoined usingjoiner. If multiplesources are specified, then the values returned by each dottedsourcepath are returned.sequence:
('sequence', expression1, expression2, ...): Applies the transform expressions in sequence. When using the sequence transformation, this should be the only top-level transformation being applied, otherwise the results cannot be guaranteed.parallel:
('multiple', expression1, expression2, ...): Applies the transform expressions in parallel. Only needed if you want to convert multiple expressions in parallel inside asequencetransform. Parallel transforms must not be mixed with other transforms at the same level.custom:
('custom', target, callable): Applies the custom transformation defined by thecallableand stores the result intarget.
- class polymatheia.transform.RecordsTransform(records, mappings)
The
RecordsTransformprovides a record transformation iterator container.The actual transformation is performed using a
Transformthat is applied to each record in the source iterator.- __init__(records, mappings)
Create a new
RecordsTransform.- Parameters:
records – The source records to iterate over and transform
mappings (
list) – The mappings that are applied to each record
- __iter__()
Return this class:~polymatheia.transform.RecordsTransform as the iterator.
- __weakref__
list of weak references to the object (if defined)
- class polymatheia.transform.RecordsTransformIterator(records, mappings)
The
RecordsTransformIteratorprovides a record transformation iterator.The actual transformation is performed using a
Transformthat is applied to each record in the source iterator.- __init__(records, mappings)
Create a new
RecordsTransformIterator.- Parameters:
records – The source records to iterate over and transform
mappings (
list) – The mappings that are applied to each record
- __iter__()
Return this class:~polymatheia.transform.RecordsTransformIterator as the iterator.
- __next__()
Transform and return the next
NavigableDictrecord.- Returns:
The transformed record
- Return type:
- Raises:
StopIteration – If no more records are available
- __weakref__
list of weak references to the object (if defined)
- class polymatheia.transform.Transform(mapping)
The
Transformis a callable transformation forNavigableDict.- __call__(record)
Transform the
recordaccording to the mappings of thisTransform.- Parameters:
record (
NavigableDict) – The record to transform- Returns:
The transformed record
- Return type:
- __init__(mapping)
Create a new
Transform.- Parameters:
mapping (
tupleorlist) – The mappings that are applied when theTransformis called. If alistis passed as the parameter, then this constructs an implicit'parallel'transform.
- __weakref__
list of weak references to the object (if defined)