# Path: pyxmpp2/etree.py
# class ElementClass:
#     def __subclasshook__(cls, other):
# def element_to_unicode(element):
# 
# Path: pyxmpp2/constants.py
# STANZA_ERROR_NS = 'urn:ietf:params:xml:ns:xmpp-stanzas'
# 
# STREAM_ERROR_NS = 'urn:ietf:params:xml:ns:xmpp-streams'
# 
# Path: pyxmpp2/constants.py
# STREAM_QNP = "{{{0}}}".format(STREAM_NS)
# 
# STANZA_ERROR_QNP = "{{{0}}}".format(STANZA_ERROR_NS)
# 
# STREAM_ERROR_QNP = "{{{0}}}".format(STREAM_ERROR_NS)
# 
# Path: pyxmpp2/constants.py
# STANZA_CLIENT_QNP = "{{{0}}}".format(STANZA_CLIENT_NS)
# 
# STANZA_SERVER_QNP = "{{{0}}}".format(STANZA_SERVER_NS)
# 
# STANZA_NAMESPACES = (STANZA_CLIENT_NS, STANZA_SERVER_NS)
# 
# Path: pyxmpp2/constants.py
# XML_LANG_QNAME = XML_QNP + "lang"
# 
# Path: pyxmpp2/xmppserializer.py
# def serialize(element):
#     """Serialize an XMPP element.
# 
#     Utility function for debugging or logging.
# 
#         :Parameters:
#             - `element`: the element to serialize
#         :Types:
#             - `element`: :etree:`ElementTree.Element`
# 
#         :Return: serialized element
#         :Returntype: `unicode`
#     """
#     if getattr(_THREAD, "serializer", None) is None:
#         _THREAD.serializer = XMPPSerializer("jabber:client")
#         _THREAD.serializer.emit_head(None, None)
#     return _THREAD.serializer.emit_stanza(element)


import logging
from .etree import ElementTree, ElementClass
from copy import deepcopy
from .constants import STANZA_ERROR_NS, STREAM_ERROR_NS
from .constants import STREAM_QNP, STANZA_ERROR_QNP, STREAM_ERROR_QNP
from .constants import STANZA_CLIENT_QNP, STANZA_SERVER_QNP, STANZA_NAMESPACES
from .constants import XML_LANG_QNAME
from .xmppserializer import serialize
            - `element`: XML element
        :Types:
            - `element`: :etree:`ElementTree.Element`

        """
        self.custom_condition.append(element)

    def serialize(self):
        """Serialize the stanza into a Unicode XML string.

        :return: serialized element.
        :returntype: `unicode`"""
        return serialize(self.as_xml())

    def as_xml(self):
        """Return the XML error representation.

        :returntype: :etree:`ElementTree.Element`"""
        result = ElementTree.Element(self.error_qname)
        result.append(deepcopy(self.condition))
        if self.text:
            text = ElementTree.SubElement(result, self.text_qname)
            if self.language:
                text.set(XML_LANG_QNAME, self.language)
            text.text = self.text
        return result

class StreamErrorElement(ErrorElement):
    """Stream error element."""
    error_qname = STREAM_QNP + "error"

# Path: pyxmpp2/etree.py
# class ElementClass:
#     def __subclasshook__(cls, other):
# def element_to_unicode(element):
# 
# Path: pyxmpp2/constants.py
# STANZA_ERROR_NS = 'urn:ietf:params:xml:ns:xmpp-stanzas'
# 
# STREAM_ERROR_NS = 'urn:ietf:params:xml:ns:xmpp-streams'
# 
# Path: pyxmpp2/constants.py
# STREAM_QNP = "{{{0}}}".format(STREAM_NS)
# 
# STANZA_ERROR_QNP = "{{{0}}}".format(STANZA_ERROR_NS)
# 
# STREAM_ERROR_QNP = "{{{0}}}".format(STREAM_ERROR_NS)
# 
# Path: pyxmpp2/constants.py
# STANZA_CLIENT_QNP = "{{{0}}}".format(STANZA_CLIENT_NS)
# 
# STANZA_SERVER_QNP = "{{{0}}}".format(STANZA_SERVER_NS)
# 
# STANZA_NAMESPACES = (STANZA_CLIENT_NS, STANZA_SERVER_NS)
# 
# Path: pyxmpp2/constants.py
# XML_LANG_QNAME = XML_QNP + "lang"
# 
# Path: pyxmpp2/xmppserializer.py
# def serialize(element):
#     """Serialize an XMPP element.
# 
#     Utility function for debugging or logging.
# 
#         :Parameters:
#             - `element`: the element to serialize
#         :Types:
#             - `element`: :etree:`ElementTree.Element`
# 
#         :Return: serialized element
#         :Returntype: `unicode`
#     """
#     if getattr(_THREAD, "serializer", None) is None:
#         _THREAD.serializer = XMPPSerializer("jabber:client")
#         _THREAD.serializer.emit_head(None, None)
#     return _THREAD.serializer.emit_stanza(element)


# Path: pyxmpp2/error.py
import logging
from .etree import ElementTree, ElementClass
from copy import deepcopy
from .constants import STANZA_ERROR_NS, STREAM_ERROR_NS
from .constants import STREAM_QNP, STANZA_ERROR_QNP, STREAM_ERROR_QNP
from .constants import STANZA_CLIENT_QNP, STANZA_SERVER_QNP, STANZA_NAMESPACES
from .constants import XML_LANG_QNAME
from .xmppserializer import serialize

            - `element`: XML element
        :Types:
            - `element`: :etree:`ElementTree.Element`

        """
        self.custom_condition.append(element)

    def serialize(self):
        """Serialize the stanza into a Unicode XML string.

        :return: serialized element.
        :returntype: `unicode`"""
        return serialize(self.as_xml())

    def as_xml(self):
        """Return the XML error representation.

        :returntype: :etree:`ElementTree.Element`"""
        result = ElementTree.Element(self.error_qname)
        result.append(deepcopy(self.condition))
        if self.text:
            text = ElementTree.SubElement(result, self.text_qname)
            if self.language:
                text.set(XML_LANG_QNAME, self.language)
            text.text = self.text
        return result

class StreamErrorElement(ErrorElement):
    """Stream error element."""
    error_qname = STREAM_QNP + "error"

    text_qname = STREAM_QNP + "text"