Validator¶
This module provides highlevel checking of parsed data for lowlevel decoders.
It handles the unicode in keys, builds dicts from flat arrays and so on.
- class ftp.decoders.validator.Field(keyword, descr, epub=None)[source]¶
This class is used to represent and parse specific “key: val” pair.
When you create the object, keyword and descr is specified. Optionally also epub parameter, which is corresponding key in EPublication structure.
Assingning value to the class is done by calling check(), which sets the value, if the key parameter matches keyword.
Parameters: - descr = None¶
Description of the data pair.
- epub = None¶
Corresponding key in EPublication structure.
- class ftp.decoders.validator.FieldParser[source]¶
Class used to make sure, that all fields in metadata are present.
See /api/required for list of required fields.
- process(key, val)[source]¶
Try to look for key in all required and optional fields. If found, set the val.
- get_epublication()[source]¶
Returns: Structure when the object is_valid(). Return type: EPublication Raises: MetaParsingException – When the object is not valid.
- ftp.decoders.validator.check_structure(data)[source]¶
Check whether the structure is flat dictionary. If not, try to convert it to dictionary.
Parameters: data – Whatever data you have (dict/tuple/list). Returns: When the conversion was successful or data was already good. Return type: dict Raises: MetaParsingException – When the data couldn’t be converted or had bad structure.