4.11. foundations.nodes

nodes.py

Platform:
Windows, Linux, Mac Os X.
Description:
This module defines various nodes and dag related classes.
Others:
Portions of the code from DAG by Simon Wittber: http://pypi.python.org/pypi/DAG/ and PyQt4 Model View Programming Tutorials by Yasin Uludag: http://www.yasinuludag.com/blog/?p=98

4.11.1. Module Attributes

foundations.nodes.LOGGER

4.11.2. Classes

class foundations.nodes.Attribute(name=None, value=None, **kwargs)[source]

Bases: foundations.dataStructures.Structure

This class represents a storage object for the AbstractNode class attributes.

Usage:

>>> attribute = Attribute(name="My Attribute", value="My Value")
>>> attribute.name
'My Attribute'
>>> attribute["name"]
'My Attribute'
>>> attribute.value
'My Value'
>>> attribute["value"]
'My Value'
Parameters:
  • name – Attribute name. ( String )
  • value – Attribute value. ( Object )
  • **kwargs – Keywords arguments. ( ** )
name[source]

This method is the property for self.__name attribute.

Returns:Value. ( String )
value[source]

This method is the property for self.__value attribute.

Returns:Value. ( Object )
class foundations.nodes.AbstractNode(*args, **kwargs)[source]

Bases: foundations.dataStructures.Structure

This class defines the base node class.
Although it can be instancied directly that class is meant to be subclassed.
Note :This class doesn’t provide compositing capabilities, AbstractCompositeNode class must be used for that purpose.

This decorator is used for execution tracing.

Parameters:
  • *args – Arguments. ( * )
  • **kwargs – Keywords arguments. ( ** )
Returns:

Object. ( Object )

family[source]

This method is the property for self.__family attribute.

Returns:self.__family. ( String )
nodesInstances[source]

This method is the property for self.__nodesInstances attribute.

Returns:self.__nodesInstances. ( WeakValueDictionary )
identity[source]

This method is the property for self.__identity attribute.

Returns:self.__identity. ( String )
name[source]

This method is the property for self.__name attribute.

Returns:self.__name. ( String )
classmethod getNodeByIdentity(*args, **kwargs)[source]

This decorator is used for execution tracing.

Parameters:
  • *args – Arguments. ( * )
  • **kwargs – Keywords arguments. ( ** )
Returns:

Object. ( Object )

listAttributes(*args, **kwargs)[source]

This decorator is used for execution tracing.

Parameters:
  • *args – Arguments. ( * )
  • **kwargs – Keywords arguments. ( ** )
Returns:

Object. ( Object )

getAttributes(*args, **kwargs)[source]

This decorator is used for execution tracing.

Parameters:
  • *args – Arguments. ( * )
  • **kwargs – Keywords arguments. ( ** )
Returns:

Object. ( Object )

attributeExists(*args, **kwargs)[source]

This decorator is used for execution tracing.

Parameters:
  • *args – Arguments. ( * )
  • **kwargs – Keywords arguments. ( ** )
Returns:

Object. ( Object )

addAttribute(*args, **kwargs)[source]

This decorator is used for execution tracing.

Parameters:
  • *args – Arguments. ( * )
  • **kwargs – Keywords arguments. ( ** )
Returns:

Object. ( Object )

removeAttribute(*args, **kwargs)[source]

This decorator is used for execution tracing.

Parameters:
  • *args – Arguments. ( * )
  • **kwargs – Keywords arguments. ( ** )
Returns:

Object. ( Object )

class foundations.nodes.AbstractCompositeNode(name=None, parent=None, children=None, **kwargs)[source]

Bases: foundations.nodes.AbstractNode

This class defines the base composite node class.
It provides compositing capabilities allowing the assembly of graphs and various trees structures.
Parameters:
  • name – Node name. ( String )
  • parent – Node parent. ( AbstractNode / AbstractCompositeNode )
  • children – Children. ( List )
  • **kwargs – Keywords arguments. ( ** )
Note :

pickle.HIGHEST_PROTOCOL must be used to pickle foundations.nodes.AbstractCompositeNode class.

parent[source]

This method is the property for self.__parent attribute.

Returns:self.__parent. ( AbstractNode / AbstractCompositeNode )
children[source]

This method is the property for self.__children attribute.

Returns:self.__children. ( List )
child(index)[source]

This method returns the child associated with given index.

Usage:

>>> nodeB = AbstractCompositeNode("MyNodeB")
>>> nodeC = AbstractCompositeNode("MyNodeC")
>>> nodeA = AbstractCompositeNode("MyNodeA", children=[nodeB, nodeC])
>>> nodeA.child(0)
<AbstractCompositeNode object at 0x10107b6f0>
>>> nodeA.child(0).name
'MyNodeB'
Parameters:index – Child index. ( Integer )
Returns:Child node. ( AbstractNode / AbstractCompositeNode / Object )
indexOf(child)[source]

This method returns the given child index.

Usage:

>>> nodeA = AbstractCompositeNode("MyNodeA")
>>> nodeB = AbstractCompositeNode("MyNodeB", nodeA)
>>> nodeC = AbstractCompositeNode("MyNodeC", nodeA)
>>> nodeA.indexOf(nodeB)
0
>>> nodeA.indexOf(nodeC)
1
Parameters:child – Child node. ( AbstractNode / AbstractCompositeNode / Object )
Returns:Child index. ( Integer )
row()[source]

This method returns the node row.

Usage:

>>> nodeA = AbstractCompositeNode("MyNodeA")
>>> nodeB = AbstractCompositeNode("MyNodeB", nodeA)
>>> nodeC = AbstractCompositeNode("MyNodeC", nodeA)
>>> nodeB.row()
0
>>> nodeC.row()
1       
Returns:Node row. ( Integer )
addChild(child)[source]

This method adds given child to the node.

Usage:

>>> nodeA = AbstractCompositeNode("MyNodeA")
>>> nodeB = AbstractCompositeNode("MyNodeB")
>>> nodeA.addChild(nodeB)
True
>>> nodeA.children
[<AbstractCompositeNode object at 0x10107afe0>]
Parameters:child – Child node. ( AbstractNode / AbstractCompositeNode / Object )
Returns:Method success. ( Boolean )
removeChild(index)[source]

This method removes child at given index from the node children.

Usage:

>>> nodeA = AbstractCompositeNode("MyNodeA")
>>> nodeB = AbstractCompositeNode("MyNodeB", nodeA)
>>> nodeC = AbstractCompositeNode("MyNodeC", nodeA)
>>> nodeA.removeChild(1)
True
>>> [child.name for child in nodeA.children]
['MyNodeB']
Parameters:index – Node index. ( Integer )
Returns:Removed child. ( AbstractNode / AbstractCompositeNode / Object )
insertChild(child, index)[source]

This method inserts given child at given index.

Usage:

>>> nodeA = AbstractCompositeNode("MyNodeA")
>>> nodeB = AbstractCompositeNode("MyNodeB", nodeA)
>>> nodeC = AbstractCompositeNode("MyNodeC", nodeA)
>>> nodeD = AbstractCompositeNode("MyNodeD")
>>> nodeA.insertChild(nodeD, 1)
True
>>> [child.name for child in nodeA.children]
['MyNodeB', 'MyNodeD', 'MyNodeC']
Parameters:
  • child – Child node. ( AbstractNode / AbstractCompositeNode / Object )
  • index – Insertion index. ( Integer )
Returns:

Method success. ( Boolean )

hasChildren()[source]

This method returns if the node has children.

Usage:

>>> nodeA = AbstractCompositeNode("MyNodeA")
>>> nodeA.hasChildren()
False
Returns:Children count. ( Integer )
childrenCount()[source]

This method returns the children count.

Usage:

>>> nodeA = AbstractCompositeNode("MyNodeA")
>>> nodeB = AbstractCompositeNode("MyNodeB", nodeA)
>>> nodeC = AbstractCompositeNode("MyNodeC", nodeA)
>>> nodeA.childrenCount()
2
Returns:Children count. ( Integer )
sortChildren(attribute=None, reverseOrder=False)[source]

This method sorts the children using either the given attribute or the node name.

Parameters:
  • attribute – Attribute name used for sorting. ( String )
  • reverseOrder – Sort in reverse order. ( Boolean )
Returns:

Method success. ( Boolean )

findChildren(pattern='.*', flags=0, candidates=None)[source]

This method finds the children matching the given patten.

Usage:

>>> nodeA = AbstractCompositeNode("MyNodeA")
>>> nodeB = AbstractCompositeNode("MyNodeB", nodeA)
>>> nodeC = AbstractCompositeNode("MyNodeC", nodeA)
>>> nodeA.findChildren("c", re.IGNORECASE)
[<AbstractCompositeNode object at 0x101078040>]
Parameters:
  • pattern – Matching pattern. ( String )
  • flags – Matching regex flags. ( Integer )
  • candidates – Matching candidates. ( List )
Returns:

Matching children. ( List )

findFamily(pattern='.*', flags=0, node=None)[source]

This method returns the nodes from given family.

Parameters:
  • pattern – Matching pattern. ( String )
  • flags – Matching regex flags. ( Integer )
  • node – Node to start walking from. ( AbstractNode / AbstractCompositeNode / Object )
Returns:

Family nodes. ( List )

listNode(tabLevel=-1)[source]

This method lists the current node and its children.

Usage:

>>> nodeA = AbstractCompositeNode("MyNodeA")
>>> nodeB = AbstractCompositeNode("MyNodeB", nodeA)
>>> nodeC = AbstractCompositeNode("MyNodeC", nodeA)
>>> print nodeA.listNode()
|----'MyNodeA'
                |----'MyNodeB'
                |----'MyNodeC'
Parameters:tabLevel – Tab level. ( Integer )
Returns:Node listing. ( String )

Table Of Contents

Previous topic

4.10. foundations.namespace

Next topic

4.12. foundations.parsers

This Page