Package pyxmpp :: Module xmlextra |
[hide private]

# Module xmlextra

source code

Extension to libxml2 for XMPP stream and stanza processing

Classes | [hide private]
| StreamHandler Base class for stream handler.
| _SAXCallback SAX events handler for the python-only stream parser.
| _PythonReader Python-only stream reader.
| StreamReader A simple push-parser interface for XML streams.

Functions | [hide private]
_escape(data) Escape data for XML | source code
_get_ns(node) Get namespace of node. | source code
replace_ns(node, old_ns, new_ns) Replace namespaces in a whole subtree. | source code
`libxml2.xmlNs` |
get_node_ns(xmlnode) Namespace of an XML node. | source code
`unicode` |
get_node_ns_uri(xmlnode) Return namespace URI of an XML node. | source code
xml_node_iter(nodelist) Iterate over sibling XML nodes. | source code
xml_element_iter(nodelist) Iterate over sibling XML elements. | source code
xml_element_ns_iter(nodelist, ns_uri) Iterate over sibling XML elements. | source code
remove_evil_characters(s) Remove control characters (not allowed in XML) from a string. | source code
`string` |
safe_serialize(xmlnode) Serialize an XML element making sure the result is sane. | source code

Variables | [hide private]
| __revision__ = ``'``$Id: xmlextra.py,v 1.15 2004/10/11 18:33:51 ja``...``
| common_doc = `libxml2.newDoc("1.0")`
| common_root = `common_doc.newChild(None, "root", None)`
| COMMON_NS = ``'``http://pyxmpp.jajcus.net/xmlns/common``'``
| common_ns = `common_root.newNs(COMMON_NS, None)`
| pure_python = `False`
| evil_characters_re = `re.compile(r'`(?u)``[`\x00`-`\x08\v\f\x0e`-`\x1f`]`')`
| utf8_replacement_char = ``'``\xef\xbf\xbd``'``
| bad_nsdef_replace_re = `re.compile(r'^`(``[^`<`]``*`<`[``^`><`]``*`\s`+``)``(`xmlns=`(``...``
| __package__ = ``'``pyxmpp``'``

Imports: sys, libxml2, threading, re, StreamParseError, _xmlextra, error, _create_reader

Function Details | [hide private]

### _get_ns(node) | source code
Get namespace of node. assigned. :returntype: `libxml2.xmlNs` Returns: the namespace object or `None` if the node has no namespace

### replace_ns(node, old_ns, new_ns) | source code
Replace namespaces in a whole subtree. The old namespace declaration will be removed if present on the `node`. Both old_ns and new_ns may be None meaning no namespace set. Parameters: `node` (`libxml2.xmlNode`) - the root of the subtree where namespaces should be replaced. `old_ns` (`libxml2.xmlNs`) - the namespace to replace. `new_ns` (`libxml2.xmlNs`) - the namespace to be used instead of old_ns.

### get_node_ns(xmlnode) | source code
Namespace of an XML node. Parameters: `xmlnode` (`libxml2.xmlNode`) - the XML node to query. Returns: `libxml2.xmlNs` namespace of the node or `None`

### get_node_ns_uri(xmlnode) | source code
Return namespace URI of an XML node. Parameters: `xmlnode` (`libxml2.xmlNode`) - the XML node to query. Returns: `unicode` namespace URI of the node or `None`

### xml_node_iter(nodelist) | source code
Iterate over sibling XML nodes. All types of nodes will be returned (not only the elements). Usually used to iterade over node's children like this:
    xml_node_iter(node.children)
Parameters: `nodelist` (`libxml2.xmlNode`) - start node of the list.

### xml_element_iter(nodelist) | source code
Iterate over sibling XML elements. Non-element nodes will be skipped. Usually used to iterade over node's children like this:
    xml_node_iter(node.children)
Parameters: `nodelist` (`libxml2.xmlNode`) - start node of the list.

### xml_element_ns_iter(nodelist, ns_uri) | source code
Iterate over sibling XML elements. Only elements in the given namespace will be returned. Usually used to iterade over node's children like this:
    xml_node_iter(node.children)
Parameters: `nodelist` (`libxml2.xmlNode`) - start node of the list.

### safe_serialize(xmlnode) | source code
Serialize an XML element making sure the result is sane. Remove control characters and invalid namespace declarations from the result string. Parameters: `xmlnode` (`libxml2.xmlNode`) - the XML element to serialize. Returns: `string` UTF-8 encoded serialized and sanitized element.

Variables Details | [hide private]

  ### __revision__ Value:
      '$Id: xmlextra.py,v 1.15 2004/10/11 18:33:51 jajcus Exp $'

  ### bad_nsdef_replace_re Value:
      re.compile(r'^([^<]*<[^><]*\s+)(xmlns=(("[^"]*")|(\'[^\']*\')))')