# Path: pyxmpp/xmlextra.py
# COMMON_NS = "http://pyxmpp.jajcus.net/xmlns/common"
# class StreamHandler:
#     class error(Exception):
#     class _SAXCallback(libxml2.SAXCallback):
#     class _PythonReader:
# class StreamReader:
#     def __init__(self):
#     def _stream_start(self,_doc):
#     def _stream_end(self,_doc):
#     def _stanza(self,_doc,_node):
#     def stream_start(self,doc):
#     def stream_end(self,doc):
#     def stanza(self, _unused, node):
#     def error(self,descr):
#     def warning(self,desc):
#     def replace_ns(node, old_ns,new_ns):
#     def _escape(data):
#         def __init__(self, handler):
#         def cdataBlock(self, data):
#         def characters(self, data):
#         def comment(self, content):
#         def endDocument(self):
#         def endElement(self, tag):
#         def error(self, msg):
#         def reference(self, name):
#         def startDocument(self):
#         def startElement(self, tag, attrs):
#         def warning(self):
#         def __init__(self,handler):
#         def feed(self, data):
#     def _get_ns(node):
#     def replace_ns(node, old_ns, new_ns):
# def get_node_ns(xmlnode):
# def get_node_ns_uri(xmlnode):
# def xml_node_iter(nodelist):
# def xml_element_iter(nodelist):
# def xml_element_ns_iter(nodelist, ns_uri):
# def remove_evil_characters(s):
# def safe_serialize(xmlnode):
#     def __init__(self,handler):
#     def doc(self):
#     def feed(self,s):


import libxml2
from pyxmpp.xmlextra import common_doc
    :Types:
        - `xmlnode`: `libxml2.xmlNode`
    """

    def as_xml(self, parent = None, doc = None):
        """Get the XML representation of `self`.

        New document will be created if no `parent` and no `doc` is given.

        :Parameters:
            - `parent`: the parent for the XML element.
            - `doc`: the document where the element should be created. If not
              given and `parent` is provided then autodetection is attempted.
              If that fails, then `common_doc` is used.
        :Types:
            - `parent`: `libxml2.xmlNode`
            - `doc`: `libxml2.xmlDoc`

        :return: the new XML element (copy of `self.xmlnode`) or document
            created (containg the copy as the root element).
        :returntype: `libxml2.xmlNode` or `libxml2.xmlDoc`"""
        if parent:
            if not doc:
                n = parent
                while n:
                    if n.type == "xml_document":
                        doc = n
                        break
                    n = n.parent
                if not doc:

# Path: pyxmpp/xmlextra.py
# COMMON_NS = "http://pyxmpp.jajcus.net/xmlns/common"
# class StreamHandler:
#     class error(Exception):
#     class _SAXCallback(libxml2.SAXCallback):
#     class _PythonReader:
# class StreamReader:
#     def __init__(self):
#     def _stream_start(self,_doc):
#     def _stream_end(self,_doc):
#     def _stanza(self,_doc,_node):
#     def stream_start(self,doc):
#     def stream_end(self,doc):
#     def stanza(self, _unused, node):
#     def error(self,descr):
#     def warning(self,desc):
#     def replace_ns(node, old_ns,new_ns):
#     def _escape(data):
#         def __init__(self, handler):
#         def cdataBlock(self, data):
#         def characters(self, data):
#         def comment(self, content):
#         def endDocument(self):
#         def endElement(self, tag):
#         def error(self, msg):
#         def reference(self, name):
#         def startDocument(self):
#         def startElement(self, tag, attrs):
#         def warning(self):
#         def __init__(self,handler):
#         def feed(self, data):
#     def _get_ns(node):
#     def replace_ns(node, old_ns, new_ns):
# def get_node_ns(xmlnode):
# def get_node_ns_uri(xmlnode):
# def xml_node_iter(nodelist):
# def xml_element_iter(nodelist):
# def xml_element_ns_iter(nodelist, ns_uri):
# def remove_evil_characters(s):
# def safe_serialize(xmlnode):
#     def __init__(self,handler):
#     def doc(self):
#     def feed(self,s):


# Path: pyxmpp/objects.py
import libxml2
from pyxmpp.xmlextra import common_doc

    :Types:
        - `xmlnode`: `libxml2.xmlNode`
    """

    def as_xml(self, parent = None, doc = None):
        """Get the XML representation of `self`.

        New document will be created if no `parent` and no `doc` is given.

        :Parameters:
            - `parent`: the parent for the XML element.
            - `doc`: the document where the element should be created. If not
              given and `parent` is provided then autodetection is attempted.
              If that fails, then `common_doc` is used.
        :Types:
            - `parent`: `libxml2.xmlNode`
            - `doc`: `libxml2.xmlDoc`

        :return: the new XML element (copy of `self.xmlnode`) or document
            created (containg the copy as the root element).
        :returntype: `libxml2.xmlNode` or `libxml2.xmlDoc`"""
        if parent:
            if not doc:
                n = parent
                while n:
                    if n.type == "xml_document":
                        doc = n
                        break
                    n = n.parent
                if not doc:

                    doc = common_doc