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.

clone()[source]
debug = False
feed(type, name, value=None)[source]

feeds an event.

This is the main entry point for user calls.

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.

setRoot(root)[source]

artificially inserts an instantiated root element.

In particular, this bypasses any checks that the event stream coming is is actually destined for root. Use this for replay-type things (feedFrom, active tags) exclusively.

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.

gavo.base.xmlstruct.parseFromString(rootStruct, inputString, context=None)[source]

parses a DaCHS RD tree rooted in rootStruct from a string.

It returns the root element of the resulting tree. You would use this like this:

parseFromString(rscdef.Column, "<column name='foo'/>")