Package nbxmpp :: Module simplexml :: Class Node |
[hide private]
[frames] | no frames]

# Class Node

source code

Node class describes syntax of separate XML Node. It have a constructor that permits node creation from set of "namespace name", attributes and payload of text strings and other nodes. It does not natively support building node from text string and uses NodeBuilder class for that purpose. After creation node can be mangled in many ways so it can be completely changed. Also node can be serialised into string in one of two modes: default (where the textual representation of node describes it exactly) and "fancy" - with whitespace added to make indentation and thus make result more readable by human.

Node class have attribute FORCE_NODE_RECREATION that is defaults to False thus enabling fast node replication from the some other node. The drawback of the fast way is that new node shares some info with the "original" node that is changing the one node may influence the other. Though it is rarely needed (in xmpppy it is never needed at all since I'm usually never using original node after replication (and using replication only to move upwards on the classes tree).

Instance Methods | [hide private]
__init__(self, tag=None, attrs=`{``}`, payload=`[``]`, parent=None, nsp=None, node_built=False, node=None) Takes "tag" argument as the name of node (prepended by namespace, if needed and separated from it by a space), attrs dictionary as the set of arguments, payload list as the set of textual strings and child nodes that this node carries within itself and "parent" argument that is another node that this one will be the child of. Also the __init__ can be provided with "node" argument that is either a text string containing exactly one node or another Node instance to begin with. If both "node" and other arguments is provided then the node initially created as replica of "node" provided and then modified to be compliant with other arguments. | source code
lookup_nsp(self, pfx=`'````'`) | source code
__str__(self, fancy=0) Method used to dump node into textual representation. If "fancy" argument is set to True produces indented output for readability | source code
addChild(self, name=None, attrs=`{``}`, payload=`[``]`, namespace=None, node=None) If "node" argument is provided, adds it as child node. Else creates new node from the other arguments' values and adds it as well | source code
addData(self, data) Add some CDATA to node | source code
clearData(self) Remove all CDATA from the node | source code
delAttr(self, key) Delete an attribute "key" | source code
delChild(self, node, attrs=`{``}`) Delete the "node" from the node's childs list, if "node" is an instance. Else delete the first node that have specified name and (optionally) attributes | source code
getAttrs(self) Return all node's attributes as dictionary | source code
getAttr(self, key) Return value of specified attribute | source code
getChildren(self) Return all node's child nodes as list | source code
getData(self) Return all node CDATA as string (concatenated) | source code
getName(self) Return the name of node | source code
getNamespace(self) Return the namespace of node | source code
getParent(self) Returns the parent of node (if present) | source code
getPayload(self) Return the payload of node i.e. list of child nodes and CDATA entries. F.e. for "<node>text1<nodea/><nodeb/> text2</node>" will be returned list: ['text1', <nodea instance>, <nodeb instance>, ' text2'] | source code
getTag(self, name, attrs=`{``}`, namespace=None) Filter all child nodes using specified arguments as filter. Return the first found or None if not found | source code
getTagAttr(self, tag, attr) Return attribute value of the child with specified name (or None if no such attribute) | source code
getTagData(self, tag) Return cocatenated CDATA of the child with specified name | source code
getTags(self, name, attrs=`{``}`, namespace=None, one=0) Filter all child nodes using specified arguments as filter. Returns the list of nodes found | source code
iterTags(self, name, attrs=`{``}`, namespace=None) Iterate over all children using specified arguments as filter | source code
setAttr(self, key, val) Set attribute "key" with the value "val" | source code
setData(self, data) Set node's CDATA to provided string. Resets all previous CDATA! | source code
setName(self, val) Change the node name | source code
setNamespace(self, namespace) Changes the node namespace | source code
setParent(self, node) Set node's parent to "node". WARNING: do not checks if the parent already present and not removes the node from the list of childs of previous parent | source code
setPayload(self, payload, add=0) Set node payload according to the list specified. WARNING: completely replaces all node's previous content. If you wish just to add child or CDATA - use addData or addChild methods | source code
setTag(self, name, attrs=`{``}`, namespace=None) Same as getTag but if the node with specified namespace/attributes not found, creates such node and returns it | source code
setTagAttr(self, tag, attr, val) Create new node (if not already present) with name "tag" and set it's attribute "attr" to value "val" | source code
setTagData(self, tag, val, attrs=`{``}`) Creates new node (if not already present) with name "tag" and (optionally) attributes "attrs" and sets it's CDATA to string "val" | source code
has_attr(self, key) Check if node have attribute "key" | source code
__getitem__(self, item) Return node's attribute "item" value | source code
__setitem__(self, item, val) Set node's attribute "item" value | source code
__delitem__(self, item) Delete node's attribute "item" | source code
__contains__(self, item) Check if node has attribute "item" | source code
__getattr__(self, attr) Reduce memory usage caused by T/NT classes - use memory only when needed | source code
Inherited from `object`: `__delattr__`, `__format__`, `__getattribute__`, `__hash__`, `__new__`, `__reduce__`, `__reduce_ex__`, `__repr__`, `__setattr__`, `__sizeof__`, `__subclasshook__`

Class Variables | [hide private]
| FORCE_NODE_RECREATION = `0`

Properties | [hide private]
Inherited from `object`: `__class__`

Method Details | [hide private]

### __init__(self, tag=None, attrs=`{``}`, payload=`[``]`, parent=None, nsp=None, node_built=False, node=None) (Constructor) | source code
Takes "tag" argument as the name of node (prepended by namespace, if needed and separated from it by a space), attrs dictionary as the set of arguments, payload list as the set of textual strings and child nodes that this node carries within itself and "parent" argument that is another node that this one will be the child of. Also the __init__ can be provided with "node" argument that is either a text string containing exactly one node or another Node instance to begin with. If both "node" and other arguments is provided then the node initially created as replica of "node" provided and then modified to be compliant with other arguments. Overrides: object.__init__

### lookup_nsp(self, pfx=`'````'`) | source code

### __str__(self, fancy=0) (Informal representation operator) | source code
Method used to dump node into textual representation. If "fancy" argument is set to True produces indented output for readability Overrides: object.__str__

### addChild(self, name=None, attrs=`{``}`, payload=`[``]`, namespace=None, node=None) | source code
If "node" argument is provided, adds it as child node. Else creates new node from the other arguments' values and adds it as well

### addData(self, data) | source code
Add some CDATA to node

### clearData(self) | source code
Remove all CDATA from the node

### delAttr(self, key) | source code
Delete an attribute "key"

### delChild(self, node, attrs=`{``}`) | source code
Delete the "node" from the node's childs list, if "node" is an instance. Else delete the first node that have specified name and (optionally) attributes

### getAttrs(self) | source code
Return all node's attributes as dictionary

### getAttr(self, key) | source code
Return value of specified attribute

### getChildren(self) | source code
Return all node's child nodes as list

### getData(self) | source code
Return all node CDATA as string (concatenated)

### getName(self) | source code
Return the name of node

### getNamespace(self) | source code
Return the namespace of node

### getParent(self) | source code
Returns the parent of node (if present)

### getPayload(self) | source code
Return the payload of node i.e. list of child nodes and CDATA entries. F.e. for "<node>text1<nodea/><nodeb/> text2</node>" will be returned list: ['text1', <nodea instance>, <nodeb instance>, ' text2']

### getTag(self, name, attrs=`{``}`, namespace=None) | source code
Filter all child nodes using specified arguments as filter. Return the first found or None if not found

### getTagAttr(self, tag, attr) | source code
Return attribute value of the child with specified name (or None if no such attribute)

### getTagData(self, tag) | source code
Return cocatenated CDATA of the child with specified name

### getTags(self, name, attrs=`{``}`, namespace=None, one=0) | source code
Filter all child nodes using specified arguments as filter. Returns the list of nodes found

### iterTags(self, name, attrs=`{``}`, namespace=None) | source code
Iterate over all children using specified arguments as filter

### setAttr(self, key, val) | source code
Set attribute "key" with the value "val"

### setData(self, data) | source code
Set node's CDATA to provided string. Resets all previous CDATA!

### setName(self, val) | source code
Change the node name

### setNamespace(self, namespace) | source code
Changes the node namespace

### setParent(self, node) | source code
Set node's parent to "node". WARNING: do not checks if the parent already present and not removes the node from the list of childs of previous parent

### setPayload(self, payload, add=0) | source code
Set node payload according to the list specified. WARNING: completely replaces all node's previous content. If you wish just to add child or CDATA - use addData or addChild methods

### setTag(self, name, attrs=`{``}`, namespace=None) | source code
Same as getTag but if the node with specified namespace/attributes not found, creates such node and returns it

### setTagAttr(self, tag, attr, val) | source code
Create new node (if not already present) with name "tag" and set it's attribute "attr" to value "val"

### setTagData(self, tag, val, attrs=`{``}`) | source code
Creates new node (if not already present) with name "tag" and (optionally) attributes "attrs" and sets it's CDATA to string "val"

### has_attr(self, key) | source code
Check if node have attribute "key"

### __getitem__(self, item) (Indexing operator) | source code
Return node's attribute "item" value

### __setitem__(self, item, val) (Index assignment operator) | source code
Set node's attribute "item" value

### __delitem__(self, item) (Index deletion operator) | source code
Delete node's attribute "item"

### __contains__(self, item) (In operator) | source code
Check if node has attribute "item"

### __getattr__(self, attr) (Qualification operator) | source code
Reduce memory usage caused by T/NT classes - use memory only when needed

Class Variable Details | [hide private]

  ### FORCE_NODE_RECREATION Value:
      0