pyxmpp.xmlextra

Package pyxmpp :: Module xmlextra |
[show private | hide private]
[frames | no frames]

## Module pyxmpp.xmlextra

Extension to libxml2 for XMPP stream and stanza processing

Classes
`StreamHandler` | Base class for stream handler.
`StreamReader` | A simple push-parser interface for XML streams.

Exceptions
`StreamParseError` | Exception raised when invalid XML is being processed.

Function Summary
`libxml2.xmlNs` | ``get_node_ns`(xmlnode)` Namespace of an XML node.
`unicode` | ``get_node_ns_uri`(xmlnode)` Return namespace URI of an XML node.
| ``remove_evil_characters`(s)` Remove control characters (not allowed in XML) from a string.
| ``replace_ns`(node, old_ns, new_ns)` Replace namespaces in a whole subtree.
`string` | ``safe_serialize`(xmlnode)` Serialize an XML element making sure the result is sane.
| ``xml_element_iter`(nodelist)` Iterate over sibling XML elements.
| ``xml_element_ns_iter`(nodelist, ns_uri)` Iterate over sibling XML elements.
| ``xml_node_iter`(nodelist)` Iterate over sibling XML nodes.

Variable Summary
`str` | `__revision__` = `'$Id: xmlextra.py,v 1.15 2004/10/11 18:33...`
`SRE_Pattern` | `bad_nsdef_replace_re` = `^([^<]*<[^><]*\s+)(xmlns=(("[^"]*...`
`xmlDoc` | `common_doc` = `<xmlDoc (None) object at 0x407b5fac>`
`xmlNs` | `common_ns` = `<xmlNs (None) object at 0x407bb08c>`
`str` | `COMMON_NS` = `'http://pyxmpp.jabberstudio.org/xmlns/common...`
`xmlNode` | `common_root` = `<xmlNode (root) object at 0x407bb06c>`
`SRE_Pattern` | `evil_characters_re` = `[\000-\010\013\014\016-\037]`
`str` | `utf8_replacement_char` = `'\xef\xbf\xbd'`

Imported modules:
  `libxml2`, `re`, `sys`, `threading`
Imported classes:
  `error`
Imported variables:
  `pure_python`

Function Details

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

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

### remove_evil_characters(s) Remove control characters (not allowed in XML) from a string.

### replace_ns(node, old_ns, new_ns) 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` - the root of the subtree where namespaces should be replaced. (type=`libxml2.xmlNode`) `old_ns` - the namespace to replace. (type=`libxml2.xmlNs`) `new_ns` - the namespace to be used instead of old_ns. (type=`libxml2.xmlNs`)

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

### xml_element_iter(nodelist) 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` - start node of the list. (type=`libxml2.xmlNode`)

### xml_element_ns_iter(nodelist, ns_uri) 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` - start node of the list. (type=`libxml2.xmlNode`)

### xml_node_iter(nodelist) 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` - start node of the list. (type=`libxml2.xmlNode`)

Variable Details

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

    ### bad_nsdef_replace_re Type: `SRE_Pattern` Value:
        ^([^<]*<[^><]*\s+)(xmlns=(("[^"]*")|('[^']*')))

    ### common_doc Type: `xmlDoc` Value:
        <xmlDoc (None) object at 0x407b5fac>

    ### common_ns Type: `xmlNs` Value:
        <xmlNs (None) object at 0x407bb08c>

    ### COMMON_NS Type: `str` Value:
        'http://pyxmpp.jabberstudio.org/xmlns/common'

    ### common_root Type: `xmlNode` Value:
        <xmlNode (root) object at 0x407bb06c>

    ### evil_characters_re Type: `SRE_Pattern` Value:
        [\000-\010\013\014\016-\037]

    ### utf8_replacement_char Type: `str` Value:
        '\xef\xbf\xbd'