# -*- coding: utf-8 -*-
"""
    pyfire.errors
    ~~~~~~~~~~~~~~~~~~~~~~

    Holds the global used base errors

    :copyright: 2011 by the pyfire Team, see AUTHORS for more details.
    :license: BSD, see LICENSE for more details.
"""

import xml.etree.ElementTree as ET


class XMPPProtocolError(Exception):
    """Base class for all errors that can be
       sent via XMPP Protocol to peer
    """

    def __init__(self, error_element, error_namespace, error_name=None):
        self.error_name = error_name
        self.element = ET.Element(error_element)
        self.element.set("xmlns", error_namespace)
        # per default all errors are recoverable
        self.unrecoverable = False

    def __unicode__(self):
        if self.error_name is not None:
            self.element.append(ET.Element(self.error_name))
        return unicode(ET.tostring(self.element))

[((22, 23, 22, 48), 'xml.etree.ElementTree.Element', 'ET.Element', ({(22, 34, 22, 47): 'error_element'}, {}), '(error_element)', True, 'import xml.etree.ElementTree as ET\n'), ((30, 23, 30, 48), 'xml.etree.ElementTree.tostring', 'ET.tostring', ({(30, 35, 30, 47): 'self.element'}, {}), '(self.element)', True, 'import xml.etree.ElementTree as ET\n'), ((29, 32, 29, 59), 'xml.etree.ElementTree.Element', 'ET.Element', ({(29, 43, 29, 58): 'self.error_name'}, {}), '(self.error_name)', True, 'import xml.etree.ElementTree as ET\n')]