Package pyxmpp :: Module exceptions

[hide private]

# Source Code for Module pyxmpp.exceptions

      1  #
      2  # (C) Copyright 2003-2006 Jacek Konieczny <jajcus@jajcus.net>
      3  #
      4  # This program is free software; you can redistribute it and/or modify
      5  # it under the terms of the GNU Lesser General Public License Version
      6  # 2.1 as published by the Free Software Foundation.
      7  #
      8  # This program is distributed in the hope that it will be useful,
      9  # but WITHOUT ANY WARRANTY; without even the implied warranty of
     10  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     11  # GNU Lesser General Public License for more details.
     12  #
     13  # You should have received a copy of the GNU Lesser General Public
     14  # License along with this program; if not, write to the Free Software
     15  # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
     16  #
     17
     18  """PyXMPP exceptions.
     19
     20  This module defines all exceptions raised by PyXMPP.
     21  """
     22
     23  __revision__="$Id: error.py 647 2006-08-26 18:27:39Z jajcus $"
     24  __docformat__="restructuredtext en"
     25
     26  import logging
     27
     28
     29 -class Error(StandardError):
     30      """Base class for all PyXMPP exceptions."""
     31      pass
     32
     33 -class JIDError(Error, ValueError):
     34      "Exception raised when invalid JID is used"
     35      pass
     36
     37 -class StreamError(Error):
     38      """Base class for all stream errors."""
     39      pass
     40
     41 -class StreamEncryptionRequired(StreamError):
     42      """Exception raised when stream encryption is requested, but not used."""
     43      pass
     44
     45 -class HostMismatch(StreamError):
     46      """Exception raised when the connected host name is other then requested."""
     47      pass
     48
     49 -class FatalStreamError(StreamError):
     50      """Base class for all fatal Stream exceptions.
     51
     52      When `FatalStreamError` is raised the stream is no longer usable."""
     53      pass
     54
     55 -class StreamParseError(FatalStreamError):
     56      """Raised when invalid XML is received in an XMPP stream."""
     57      pass
     58
     59 -class StreamAuthenticationError(FatalStreamError):
     60      """Raised when stream authentication fails."""
     61      pass
     62
     63 -class TLSNegotiationFailed(FatalStreamError):
     64      """Raised when stream TLS negotiation fails."""
     65      pass
     66
     67 -class TLSError(FatalStreamError):
     68      """Raised on TLS error during stream processing."""
     69      pass
     70
     71 -class TLSNegotiatedButNotAvailableError(TLSError):
     72      """Raised on TLS error during stream processing."""
     73      pass
     74
     75 -class SASLNotAvailable(StreamAuthenticationError):
     76      """Raised when SASL authentication is requested, but not available."""
     77      pass
     78
     79 -class SASLMechanismNotAvailable(StreamAuthenticationError):
     80      """Raised when none of SASL authentication mechanisms requested is
     81      available."""
     82      pass
     83
     84 -class SASLAuthenticationFailed(StreamAuthenticationError):
     85      """Raised when stream SASL authentication fails."""
     86      pass
     87
     88 -class StringprepError(Error):
     89      """Exception raised when string preparation results in error."""
     90      pass
     91
     92 -class ClientError(Error):
     93      """Raised on a client error."""
     94      pass
     95
     96 -class FatalClientError(ClientError):
     97      """Raised on a fatal client error."""
     98      pass
     99
    100 -class ClientStreamError(StreamError):
    101      """Raised on a client stream error."""
    102      pass
    103
    104 -class FatalClientStreamError(FatalStreamError):
    105      """Raised on a fatal client stream error."""
    106      pass
    107
    108 -class LegacyAuthenticationError(ClientStreamError):
    109      """Raised on a legacy authentication error."""
    110      pass
    111
    112 -class RegistrationError(ClientStreamError):
    113      """Raised on a in-band registration error."""
    114      pass
    115
    116 -class ComponentStreamError(StreamError):
    117      """Raised on a component error."""
    118      pass
    119
    120 -class FatalComponentStreamError(ComponentStreamError,FatalStreamError):
    121      """Raised on a fatal component error."""
    122      pass
    123
    124  ########################
    125  # Protocol Errors
    126
    127 -class ProtocolError(Error):
    128      """Raised when there is something wrong with a stanza processed.
    129
    130      When not processed earlier by an application, the exception will be catched
    131      by the stanza dispatcher to return XMPP error to the stanza sender, when
    132      allowed.
    133
    134      ProtocolErrors handled internally by PyXMPP will be logged via the logging
    135      interface. Errors reported to the sender will be logged using
    136      "pyxmpp.ProtocolError.reported" channel and the ignored errors using
    137      "pyxmpp.ProtocolError.ignored" channel. Both with the "debug" level.
    138
    139      :Ivariables:
    140          - `xmpp_name` -- XMPP error name which should be reported.
    141          - `message` -- the error message."""
    142
    143      logger_reported = logging.getLogger("pyxmpp.ProtocolError.reported")
    144      logger_ignored = logging.getLogger("pyxmpp.ProtocolError.ignored")
    145
    146 -    def __init__(self, xmpp_name, message):
    147          self.args = (xmpp_name, message)
    148      @property
    149 -    def xmpp_name(self):
    150          return self.args[0]
    151      @property
    152 -    def message(self):
    153          return self.args[1]
    154 -    def log_reported(self):
    155          self.logger_reported.debug(u"Protocol error detected: %s", self.message)
    156 -    def log_ignored(self):
    157          self.logger_ignored.debug(u"Protocol error detected: %s", self.message)
    158 -    def __unicode__(self):
    159          return str(self.args[1])
    160 -    def __repr__(self):
    161          return "<ProtocolError %r %r>" % (self.xmpp_name, self.message)
    162
    163 -class BadRequestProtocolError(ProtocolError):
    164      """Raised when invalid stanza is processed and 'bad-request' error should be reported."""
    165 -    def __init__(self, message):
    166          ProtocolError.__init__(self, "bad-request", message)
    167
    168 -class JIDMalformedProtocolError(ProtocolError, JIDError):
    169      """Raised when invalid JID is encountered."""
    170 -    def __init__(self, message):
    171          ProtocolError.__init__(self, "jid-malformed", message)
    172
    173 -class FeatureNotImplementedProtocolError(ProtocolError):
    174      """Raised when stanza requests a feature which is not (yet) implemented."""
    175 -    def __init__(self, message):
    176          ProtocolError.__init__(self, "feature-not-implemented", message)
    177
    178  # vi: sts=4 et sw=4
    179