gavo.base.xmlstruct module¶
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.
- class gavo.base.xmlstruct.EventProcessor(rootStruct, ctx)[source]¶
Bases:
object
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.
- debug = False¶
- gavo.base.xmlstruct.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).
- gavo.base.xmlstruct.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.