xsdata.formats.dataclass.parsers module¶
-
class
xsdata.formats.dataclass.parsers.
JsonParser
(name_generator=<function ModelInspect.<lambda>>, cache=<factory>)[source]¶ Bases:
xsdata.formats.mixins.AbstractParser
,xsdata.formats.dataclass.mixins.ModelInspect
-
parse
(source, clazz)[source]¶ Parse the JSON input stream and return the resulting object tree.
- Return type
~T
-
parse_context
(data, clazz)[source]¶ Recursively build the given model from the input dict data.
- Raises
TypeError – When parsing fails for any reason
- 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
- Return type
-
static
get_value
(data, field)[source]¶ Find the field value in the given dictionary or return the default field value.
-
cache
= None¶
-
-
class
xsdata.formats.dataclass.parsers.
QueueItem
(index, position, default=None, qname=None, meta=None, types=<factory>)[source]¶ Bases:
object
-
index
: int = None¶
-
position
: int = None¶
-
default
: Any = None¶
-
qname
: Optional[str] = None¶
-
meta
: Optional[xsdata.formats.dataclass.mixins.ClassMeta] = None¶
-
types
: List[Type] = None¶
-
-
class
xsdata.formats.dataclass.parsers.
XmlParser
(name_generator=<function ModelInspect.<lambda>>, cache=<factory>, index=<factory>)[source]¶ Bases:
xsdata.formats.mixins.AbstractXmlParser
,xsdata.formats.dataclass.mixins.ModelInspect
-
index
: int = None¶
-
queue
: List[Optional[QueueItem]] = None¶
-
namespace
: Optional[str] = None¶
-
objects
: List[Tuple[QName, Any]] = None¶
-
parse_context
(context, clazz)[source]¶ Dispatch elements to handlers as they arrive and are fully parsed.
Initialize queue with clazz metadata and reset pending objects list.
- Raises
ValueError – When the requested type doesn’t match the result object
- Return type
~T
-
start_node
(element)[source]¶ Queue the necessary metadata to bind the given element when it’s fully parsed.
Checks for the last item in queue: - Is none or has none meta -> inside a wildcard - Element tag exists in known variables -> dataclass or primitive - Element tag equals meta qualified name -> root element - Element tag unknown but queue supports wildcard -> start a wildcard
- Raises
Value – When the parser doesn’t know how to handle the given element.
-
end_node
(element)[source]¶ Build an objects tree for the given element.
Construct a dataclass instance with the attributes of the given element and any pending objects that belong to the model. Otherwise parse as a primitive type the element’s text content.
- Returns object
A dataclass object or a python primitive value.
- Return type
Optional
[~T]
-
emit_event
(event, name, **kwargs)[source]¶ Call if exist the parser’s hook for the given element and event.
-
fetch_class_children
(item, element)[source]¶ Return a dictionary of qualified object names and their values for the given queue item.
- Raises
ValueError – if queue item type is primitive.
- Return type
-
bind_element_attrs
(metadata, element)[source]¶ Parse the given element’s attributes and any text content and return a dictionary of field names and values based on the given class metadata.
- Return type
-