schematics_xml package

Submodules

schematics_xml.models module

schematics_xml.models

Base models that provide to/from XML methods.

class schematics_xml.models.XMLModel(raw_data=None, trusted_data=None, deserialize_mapping=None, init=True, partial=True, strict=True, validate=False, app_data=None, **kwargs)[source]

Bases: schematics.models.Model

A model that can convert it’s fields to and from XML.

classmethod from_xml(xml: str) → schematics.models.Model[source]

Convert XML into a model.

Parameters:xml – A string of XML that represents this Model.
primitive_to_xml(primitive: dict, parent: 'lxml.etree._Element'=None)[source]
primitive_value_to_xml(key, parent, value)[source]
to_xml(role: str=None, app_data: dict=None, encoding: str=None, **kwargs) → str[source]

Return a string of XML that represents this model.

Currently all arguments are passed through to schematics.Model.to_primitive.

Parameters:
  • role – schematics Model to_primitive role parameter.
  • app_data – schematics Model to_primitive app_data parameter.
  • encoding – xml encoding attribute string.
  • kwargs – schematics Model to_primitive kwargs parameter.
xml_encoding = 'UTF-8'

Override this attribute to set the encoding specified in the XML returned by XMLModel.to_xml().

xml_root

Override this attribute to set the XML root returned by XMLModel.to_xml().

schematics_xml.models.ensure_lists_in_model(raw_data: dict, model_cls: schematics_xml.models.XMLModel)[source]

Ensure that single item lists are represented as lists and not dicts.

In XML single item lists are converted to dicts by xmltodict - there is essentially no way for xmltodict to know that it should be a list not a dict.

Parameters:
  • raw_data
  • model_cls
schematics_xml.models.ensure_lists_in_value(value: 'typing.Any', field: schematics.types.base.BaseType)[source]
schematics_xml.models.field_has_type(needle: schematics.types.base.BaseType, field: schematics.types.base.BaseType) → bool[source]

Return True if field haystack contains a field of type needle.

Parameters:
  • needle – A schematics field class to search for.
  • haystack – An instance of a schematics field within a model.
schematics_xml.models.model_has_field_type(needle: schematics.types.base.BaseType, haystack: schematics.models.Model) → bool[source]

Return True if haystack contains a field of type needle.

Iterates over all fields (and into field if appropriate) and searches for field type needle in model haystack.

Parameters:
  • needle – A schematics field class to search for.
  • haystack – A schematics model to search within.

Module contents

Python schematics models for converting to and from XML.

class schematics_xml.VersionInfo(major, minor, micro, releaselevel, serial)

Bases: tuple

major

Alias for field number 0

micro

Alias for field number 2

minor

Alias for field number 1

releaselevel

Alias for field number 3

serial

Alias for field number 4