nodes.py
Bases: foundations.dataStructures.Structure
Defines a storage object for the AbstractNode class attributes.
Initializes the class.
Usage:
>>> attribute = Attribute(name="My Attribute", value="My Value")
>>> attribute.name
u'My Attribute'
>>> attribute["name"]
u'My Attribute'
>>> attribute.value
u'My Value'
>>> attribute["value"]
u'My Value'
Parameters: |
---|
Bases: foundations.dataStructures.Structure
Note: | Doesn’t provide compositing capabilities, AbstractCompositeNode class must be used for that purpose. |
---|
Initializes the class.
Usage:
>>> nodeA = AbstractNode("MyNodeA")
>>> nodeA.identity
1
>>> nodeB = AbstractNode()
>>> nodeB.name
u'Abstract2'
>>> nodeB.identity
2
Parameters: |
|
---|
Property for self.__nodesInstances attribute.
Returns: | self.__nodesInstances. |
---|---|
Return type: | WeakValueDictionary |
Property for self.__identity attribute.
Returns: | self.__identity. |
---|---|
Return type: | unicode |
Returns the Node with given identity.
Usage:
>>> nodeA = AbstractNode("MyNodeA")
>>> AbstractNode.getNodeByIdentity(1)
<AbstractNode object at 0x101043a80>
Parameters: | identity (int) – Node identity. |
---|---|
Returns: | Node. |
Return type: | AbstractNode |
Note: | Nodes identities are starting from ‘1’ to nodes instances count. |
Returns the Node attributes names.
Usage:
>>> nodeA = AbstractNode("MyNodeA", attributeA=Attribute(), attributeB=Attribute())
>>> nodeA.listAttributes()
['attributeB', 'attributeA']
Returns: | Attributes names. |
---|---|
Return type: | list |
Returns the Node attributes.
Usage:
>>> nodeA = AbstractNode("MyNodeA", attributeA=Attribute(value="A"), attributeB=Attribute(value="B"))
>>> nodeA.getAttributes()
[<Attribute object at 0x7fa471d3b5e0>, <Attribute object at 0x101e6c4a0>]
Returns: | Attributes. |
---|---|
Return type: | list |
Returns if given attribute exists in the node.
Usage:
>>> nodeA = AbstractNode("MyNodeA", attributeA=Attribute(), attributeB=Attribute())
>>> nodeA.attributeExists("attributeA")
True
>>> nodeA.attributeExists("attributeC")
False
Parameters: | name (unicode) – Attribute name. |
---|---|
Returns: | Attribute exists. |
Return type: | bool |
Adds given attribute to the node.
Usage:
>>> nodeA = AbstractNode()
>>> nodeA.addAttribute("attributeA", Attribute())
True
>>> nodeA.listAttributes()
[u'attributeA']
Parameters: |
|
---|---|
Returns: | Method success. |
Return type: | bool |
Removes given attribute from the node.
Usage:
>>> nodeA = AbstractNode("MyNodeA", attributeA=Attribute(), attributeB=Attribute())
>>> nodeA.removeAttribute("attributeA")
True
>>> nodeA.listAttributes()
['attributeB']
Parameters: | name (unicode) – Attribute name. |
---|---|
Returns: | Method success. |
Return type: | bool |
Bases: foundations.nodes.AbstractNode
Initializes the class.
Parameters: | |
---|---|
Note: | pickle.HIGHEST_PROTOCOL must be used to pickle foundations.nodes.AbstractCompositeNode class. |
Property for self.__parent attribute.
Returns: | self.__parent. |
---|---|
Return type: | AbstractNode or AbstractCompositeNode |
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
u'MyNodeB'
Parameters: | index (int) – Child index. |
---|---|
Returns: | Child node. |
Return type: | AbstractNode or AbstractCompositeNode or Object |
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 (AbstractNode or AbstractCompositeNode or Object) – Child node. |
---|---|
Returns: | Child index. |
Return type: | int |
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. |
---|---|
Return type: | int |
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 (AbstractNode or AbstractCompositeNode or Object) – Child node. |
---|---|
Returns: | Method success. |
Return type: | bool |
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]
[u'MyNodeB']
Parameters: | index (int) – Node index. |
---|---|
Returns: | Removed child. |
Return type: | AbstractNode or AbstractCompositeNode or Object |
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]
[u'MyNodeB', u'MyNodeD', u'MyNodeC']
Parameters: |
|
---|---|
Returns: | Method success. |
Return type: | bool |
Returns if the Node has children.
Usage:
>>> nodeA = AbstractCompositeNode("MyNodeA")
>>> nodeA.hasChildren()
False
Returns: | Children count. |
---|---|
Return type: | int |
Returns the children count.
Usage:
>>> nodeA = AbstractCompositeNode("MyNodeA")
>>> nodeB = AbstractCompositeNode("MyNodeB", nodeA)
>>> nodeC = AbstractCompositeNode("MyNodeC", nodeA)
>>> nodeA.childrenCount()
2
Returns: | Children count. |
---|---|
Return type: | int |
Sorts the children using either the given attribute or the Node name.
Parameters: | |
---|---|
Returns: | Method success. |
Return type: | bool |
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: | |
---|---|
Returns: | Matching children. |
Return type: | list |
Returns the Nodes from given family.
Parameters: | |
---|---|
Returns: | Family nodes. |
Return type: | list |
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 (int) – Tab level. |
---|---|
Returns: | Node listing. |
Return type: | unicode |