Code to parse structures from XML sources.
The purpose of much of the mess here is to symmetrized XML attributes and values. Basically, we want start, value, end events whether or not a piece of data comes in an element with a certain tag name or via a named attribute.
A dispatcher for parse events to structures.
It is constructed with the root structure of the result tree, either as a type or as an instance.
After that, events can be fed to the feed method that makes sure they are routed to the proper object.
feedEvent(ctx, evType, name, value)[source]¶
dispatches an event to the root structure.
Do not call this yourself unless you know what you’re doing. The method to feed “real” events to is feed.
feedTo(rootStruct, eventSource, context, feedInto=False)[source]¶
feeds events from eventSource to rootStruct.
A new event processor is used for feeding. No context exit functions are run.
The processed root structure is returned.
if feedInto is true, the event creating the root structure is not expected (TODO: this is crap; fix it so that this is always the case when rootStruct is an instance).
parseFromStream(rootStruct, inputStream, context=None)[source]¶
parses a tree rooted in rootStruct from some file-like object inputStream.
It returns the root element of the resulting tree. If rootStruct is a type subclass, it will be instantiated to create a root element, if it is an instance, this instance will be the root.