# 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 unittest
import libxml2
from pyxmpp import xmlextra
from stream_reader import xml_elements_equal
                    n1_ns = None
                if n1_ns is None:
                    xmlextra.replace_ns(n1, n1_ns, common_ns)
            n = n.next
        self.failUnless(xml_elements_equal(root, output_root))

    def test_safe_serialize(self):
        s1 = """<a xmlns="http://pyxmpp.jajcus.net/xmlns/test"><b a1="v1" xmlns="http://pyxmpp.jajcus.net/xmlns/test1" a2="v2"/></a>"""
        doc1 = libxml2.parseDoc(s1)
        root1 = doc1.getRootElement()
        el1 = root1.children
        try:
            root1_ns = root1.ns()
        except libxml2.treeError:
            root1_ns = None
        el1.setNs(root1_ns)

        #s = el1.serialize()
        s = xmlextra.safe_serialize(el1)

        s2 = '<a xmlns="http://pyxmpp.jajcus.net/xmlns/test">%s</a>' % (s,)

        doc2 = libxml2.parseDoc(s2)
        root2 = doc2.getRootElement()
        self.failUnless(xml_elements_equal(root1, root2))


def suite():
     suite = unittest.TestSuite()
     suite.addTest(unittest.makeSuite(TestReplaceNs))

# 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: tests/ns_operations.py
import unittest
import libxml2
from pyxmpp import xmlextra
from stream_reader import xml_elements_equal

                    n1_ns = None
                if n1_ns is None:
                    xmlextra.replace_ns(n1, n1_ns, common_ns)
            n = n.next
        self.failUnless(xml_elements_equal(root, output_root))

    def test_safe_serialize(self):
        s1 = """<a xmlns="http://pyxmpp.jajcus.net/xmlns/test"><b a1="v1" xmlns="http://pyxmpp.jajcus.net/xmlns/test1" a2="v2"/></a>"""
        doc1 = libxml2.parseDoc(s1)
        root1 = doc1.getRootElement()
        el1 = root1.children
        try:
            root1_ns = root1.ns()
        except libxml2.treeError:
            root1_ns = None
        el1.setNs(root1_ns)

        #s = el1.serialize()
        s = xmlextra.safe_serialize(el1)

        s2 = '<a xmlns="http://pyxmpp.jajcus.net/xmlns/test">%s</a>' % (s,)

        doc2 = libxml2.parseDoc(s2)
        root2 = doc2.getRootElement()
        self.failUnless(xml_elements_equal(root1, root2))


def suite():
     suite = unittest.TestSuite()
     suite.addTest(unittest.makeSuite(TestReplaceNs))

     return suite