pfif module¶
PFIF 1.1 - 1.4 parsing and serialization (see http://zesty.ca/pfif/).
This module converts between PFIF XML documents (PFIF 1.1, 1.2, 1.3, or 1.4) and plain Python dictionaries that have PFIF 1.4 field names as keys (always 1.4) and Unicode strings as values. Some useful constants are also defined here according to the PFIF specification. Use parse() to parse PFIF 1.1, 1.2, 1.3, or 1.4; use PFIF_1_1, PFIF_1_2, PFIF_1_3, or PFIF_1_4 to serialize to the desired version.
-
class
pfif.Handler(rename_fields=True)[source]¶ Bases:
xml.sax.handler.ContentHandlerSAX event handler for parsing PFIF documents.
-
class
pfif.PfifVersion(version, ns, fields, mandatory_fields, serializers)[source]¶ -
check_tag((ns, local), parent=None)[source]¶ Given a namespace-qualified tag and its parent, returns the PFIF type or field name if the tag is valid, or None if the tag is not recognized.
-
entity_to_dict(entity, fields)[source]¶ Converts a person or note record from a Python object (with PFIF 1.4 field names as attributes) to a Python dictionary (with the given field names as keys, and Unicode strings as values).
-
-
pfif.convert_description_to_other(desc)[source]¶ Converts ‘description’ in PFIF 1.4 to ‘other’ in older versions.
-
pfif.maybe_convert_other_to_description(other)[source]¶ Converts ‘other’ in PFIF 1.3 and earlier to ‘description’ in PFIF 1.4 if ‘other’ has only ‘description’ field. Otherwise it returns ‘other’ without modifying it, so we don’t lose any information.
-
pfif.parse(pfif_text, rename_fields=True)[source]¶ Takes the text of a PFIF document, as a Unicode string or UTF-8 string, and returns a list of person records and a list of note records. Each record is a plain dictionary of strings, with PFIF 1.4 field names as keys if rename_fields is True; otherwise, the field names are kept as is in the input XML file.
-
pfif.parse_file(pfif_utf8_file, rename_fields=True)[source]¶ Reads a UTF-8-encoded PFIF file to give a list of person records and a list of note records. Each record is a plain dictionary of strings, with PFIF 1.4 field names as keys if rename_fields is True; otherwise, the field names are kept as is in the input XML file.