xsdata.formats.dataclass.parsers package

Subpackages

Submodules

Module contents

class xsdata.formats.dataclass.parsers.JsonParser(context=<factory>)[source]

Bases: xsdata.formats.bindings.AbstractParser

Json parsing and binding for dataclasses.

Parameters

context (XmlContext) – Model metadata builder

context: xsdata.formats.dataclass.context.XmlContext
from_path(path, clazz)[source]

Parse the input file path and return the resulting object tree.

Parameters
Return type

~T

parse(source, clazz)[source]

Parse the JSON input stream and return the resulting object tree.

Parameters
  • source (BytesIO) –

  • clazz (Type[~T]) –

Return type

~T

parse_context(data, clazz)[source]

Recursively build the given model from the input dict data.

Raises

ParserError – When parsing fails for any reason

Parameters
Return type

~T

bind_value(var, value)[source]

Bind value according to the class var.

The return value can be: - a dataclass instance - a dictionary with unknown attributes - a list of unknown elements - an enumeration - a primitive value

Parameters
Return type

Any

bind_wildcard(value)[source]
Parameters

value (Any) –

Return type

Any

bind_choice(value, var)[source]
Parameters
Return type

Any

static get_value(data, var)[source]

Find the var value in the given dictionary or return the default var value.

Parameters
Return type

Any

class xsdata.formats.dataclass.parsers.XmlParser(config=<factory>, context=<factory>, handler=<class 'xsdata.formats.dataclass.parsers.handlers.lxml.LxmlEventHandler'>)[source]

Bases: xsdata.formats.dataclass.parsers.nodes.NodeParser

Bind xml nodes to dataclasses with event hooks.

Parameters
handler

alias of xsdata.formats.dataclass.parsers.handlers.lxml.LxmlEventHandler

emit_cache: Dict
start(clazz, queue, objects, qname, attrs, ns_map)[source]

Queue the next xml node for parsing.

Emit a start event with the current element qualified name and attributes.

Parameters
end(queue, objects, qname, text, tail)[source]

Parse the last xml node and bind any intermediate objects.

Emit an end event with the result object if any.

Return type

Any

Returns

The result of the binding process.

Parameters
emit_event(event, name, **kwargs)[source]

Call if exist the parser’s hook for the given element and event.

Parameters
  • event (str) –

  • name (str) –

  • kwargs (Any) –