The Transform class¶
pyxsd.transforms.Transform is the abstract base every transform inherits
from. It provides tree access and node-manufacturing helpers; anything you
add to it must operate only on the generic node shape so it applies to all
transforms.
- class pyxsd.transforms.transform.Transform(root)[source]¶
The base abstract class for all transforms.
All methods should mix into the usable transform classes. Contains methods to retrieve elements from the tree.
Subclasses must accept the tree root in their
__init__; that makes the class abstract until it does, so framework-only subclasses (likeDisplayer) cannot be instantiated by accident. Subclasses should callsuper().__init__(root), which stores the root asself.root.- Parameters:
root (Any)
- iter_tree(instance)[source]¶
Yield every tree node at or below
instance, depth-first.Method form of the module-level
iter_tree(); see there for semantics.instance: a tree node, or a list/dict of them.
- walk(instance, visitor, *args, **kwargs)[source]¶
Walks through the tree structure and runs a provided visitor function on all elements.
The visitor is called as
visitor(node, attrNames, elemNames, *args, **kwargs)wherenodeis the tree node being visited,attrNamesis the list of its attribute names, andelemNamesis the list of its children’s names. Traversal is driven byiter_tree().
- classCollector(instance, attrNames, elemNames, collectorDict)[source]¶
Visitor function to make a dictionary that associates a class with its instances.
The class name is the key, and the value is the list of associated instances. See
getInstancesByClassName.
- tagCollector(instance, attrNames, elemNames, collectorDict)[source]¶
A visitor function that is used to make a dictionary that associates a tag name with its children.
See
getAllSubElements.
- tagFinder(instance, attrNames, elemNames, collection, name)[source]¶
A visitor function to collect all tags with a particular name and put them into a list.
See
getElementsByName.
- getInstancesByClassName(root)[source]¶
Uses the
walkfunction with theclassCollectorvisitor function to associate a class name with the class’s instances.
- getAllSubElements(root)[source]¶
Uses the
walkfunction with thetagCollectorvisitor function to make a dictionary that associates all elements with their sub-elements.
- getElementsByName(root, name)[source]¶
Uses the
walkfunction with thetagFindervisitor function to make a list containing all elements with a particular name.
Tree iteration¶
- pyxsd.transforms.transform.iter_tree(instance)[source]¶
Yield every tree node at or below
instance, depth-first.Lists (and tuples) are descended into item by item and dictionaries by value; anything without both
_children_and_attribs_is skipped. Each yielded node is visited before its children (pre-order). This generator powerswalk()and is the supported way to iterate a tree directly:for node in iter_tree(root): ...
instance: a tree node, or a list/dict of them.