A Role object can be used to filter specific fields against a sequence.
The Role is two things: a set of names and a function. The function describes how filter taking a field name as input and then returning either True or False, indicating that field should or should not be skipped.
A Role can be operated on as a Set object representing the fields is has an opinion on. When Roles are combined with other roles, the filtering behavior of the first role is used.
Implements the behavior of a blacklist by requesting a field be skipped whenever it’s name is found in the list of fields.
Parameters: |
|
---|
Implements the behavior of a whitelist by requesting a field be skipped whenever it’s name is not in the list of fields.
Parameters: |
|
---|
Accepts a field name, value, and a field list. This functions implements acceptance of all fields by never requesting a field be skipped, thus returns False for all input.
Parameters: |
|
---|
This function inspects a model and a field for a setting either at the model or field level for the serialize_when_none setting.
The setting defaults to the value of the class. A field can override the class setting with it’s own serialize_when_none setting.
Parameters: |
|
---|
Iterator for the atomic components of a model definition and relevant data that creates a threeple of the field’s name, the instance of it’s type, and it’s value.
Parameters: |
|
---|
Returns a function that operates as a blacklist for the provided list of fields.
A blacklist is a list of fields explicitly named that are not allowed.
Expands a flattened structure into it’s corresponding layers. Essentially, it is the counterpart to flatten_to_dict.
Parameters: |
|
---|
The apply shape function is intended to be a general loop definition that can be used for any form of data shaping, such as application of roles or how a field is transformed.
Parameters: |
|
---|
Produces a flat dictionary representation of the model. Flat, in this context, means there is only one level to the dictionary. Multiple layers are represented by the structure of the key.
Example:
>>> class Foo(Model):
... s = StringType()
... l = ListType(StringType)
>>> f = Foo()
>>> f.s = 'string'
>>> f.l = ['jms', 'was here', 'and here']
>>> flatten(Foo, f)
{'s': 'string', u'l.1': 'jms', u'l.0': 'was here', u'l.2': 'and here'}
Parameters: |
|
---|
Flattens an iterable structure into a single layer dictionary.
For example:
- {
- ‘s’: ‘jms was hrrr’, ‘l’: [‘jms was here’, ‘here’, ‘and here’]
}
becomes
- {
- ‘s’: ‘jms was hrrr’, u’l.1’: ‘here’, u’l.0’: ‘jms was here’, u’l.2’: ‘and here’
}
Parameters: |
|
---|
The import loop is designed to take untrusted data and convert it into the native types, as described in cls. It does this by calling field_converter on every field.
Errors are aggregated and returned by throwing a ModelConversionError.
Parameters: |
|
---|
Implements serialization as a mechanism to convert Model instances into dictionaries keyed by field_names with the converted data as the values.
The conversion is done by calling to_primitive on both model and field instances.
Parameters: |
|
---|
Returns a function that operates as a whitelist for the provided list of fields.
A whitelist is a list of fields explicitly named that are allowed.
Returns a function that evicts nothing. Exists mainly to be an explicit allowance of all fields instead of a using an empty blacklist.
To learn more about how Transforms are used, visit Using Importing and Using Exporting