Package pyxmpp :: Module exceptions
[hide private]

Source Code for Module pyxmpp.exceptions

  1  # 
  2  # (C) Copyright 2003-2010 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  __docformat__="restructuredtext en" 
 24   
 25  import logging 
26 27 28 -class Error(StandardError):
29 """Base class for all PyXMPP exceptions.""" 30 pass
31
32 -class JIDError(Error, ValueError):
33 "Exception raised when invalid JID is used" 34 pass
35
36 -class StreamError(Error):
37 """Base class for all stream errors.""" 38 pass
39
40 -class StreamEncryptionRequired(StreamError):
41 """Exception raised when stream encryption is requested, but not used.""" 42 pass
43
44 -class HostMismatch(StreamError):
45 """Exception raised when the connected host name is other then requested.""" 46 pass
47
48 -class FatalStreamError(StreamError):
49 """Base class for all fatal Stream exceptions. 50 51 When `FatalStreamError` is raised the stream is no longer usable.""" 52 pass
53
54 -class StreamParseError(FatalStreamError):
55 """Raised when invalid XML is received in an XMPP stream.""" 56 pass
57
58 -class DNSError(FatalStreamError):
59 """Raised when no host name could be resolved for the target.""" 60 pass
61
62 -class UnexpectedCNAMEError(DNSError):
63 """Raised when CNAME record was found when A or AAAA was expected.""" 64 pass
65
66 -class StreamAuthenticationError(FatalStreamError):
67 """Raised when stream authentication fails.""" 68 pass
69
70 -class TLSNegotiationFailed(FatalStreamError):
71 """Raised when stream TLS negotiation fails.""" 72 pass
73
74 -class TLSError(FatalStreamError):
75 """Raised on TLS error during stream processing.""" 76 pass
77
78 -class TLSNegotiatedButNotAvailableError(TLSError):
79 """Raised on TLS error during stream processing.""" 80 pass
81
82 -class SASLNotAvailable(StreamAuthenticationError):
83 """Raised when SASL authentication is requested, but not available.""" 84 pass
85
86 -class SASLMechanismNotAvailable(StreamAuthenticationError):
87 """Raised when none of SASL authentication mechanisms requested is 88 available.""" 89 pass
90
91 -class SASLAuthenticationFailed(StreamAuthenticationError):
92 """Raised when stream SASL authentication fails.""" 93 pass
94
95 -class StringprepError(Error):
96 """Exception raised when string preparation results in error.""" 97 pass
98
99 -class ClientError(Error):
100 """Raised on a client error.""" 101 pass
102
103 -class FatalClientError(ClientError):
104 """Raised on a fatal client error.""" 105 pass
106
107 -class ClientStreamError(StreamError):
108 """Raised on a client stream error.""" 109 pass
110
111 -class FatalClientStreamError(FatalStreamError):
112 """Raised on a fatal client stream error.""" 113 pass
114
115 -class LegacyAuthenticationError(ClientStreamError):
116 """Raised on a legacy authentication error.""" 117 pass
118
119 -class RegistrationError(ClientStreamError):
120 """Raised on a in-band registration error.""" 121 pass
122
123 -class ComponentStreamError(StreamError):
124 """Raised on a component error.""" 125 pass
126
127 -class FatalComponentStreamError(ComponentStreamError,FatalStreamError):
128 """Raised on a fatal component error.""" 129 pass
130
131 ######################## 132 # Protocol Errors 133 134 -class ProtocolError(Error):
135 """Raised when there is something wrong with a stanza processed. 136 137 When not processed earlier by an application, the exception will be catched 138 by the stanza dispatcher to return XMPP error to the stanza sender, when 139 allowed. 140 141 ProtocolErrors handled internally by PyXMPP will be logged via the logging 142 interface. Errors reported to the sender will be logged using 143 "pyxmpp.ProtocolError.reported" channel and the ignored errors using 144 "pyxmpp.ProtocolError.ignored" channel. Both with the "debug" level. 145 146 :Ivariables: 147 - `xmpp_name` -- XMPP error name which should be reported. 148 - `message` -- the error message.""" 149 150 logger_reported = logging.getLogger("pyxmpp.ProtocolError.reported") 151 logger_ignored = logging.getLogger("pyxmpp.ProtocolError.ignored") 152
153 - def __init__(self, xmpp_name, message):
154 self.args = (xmpp_name, message)
155 @property
156 - def xmpp_name(self):
157 return self.args[0]
158 @property
159 - def message(self):
160 return self.args[1]
161 - def log_reported(self):
162 self.logger_reported.debug(u"Protocol error detected: %s", self.message)
163 - def log_ignored(self):
164 self.logger_ignored.debug(u"Protocol error detected: %s", self.message)
165 - def __unicode__(self):
166 return str(self.args[1])
167 - def __repr__(self):
168 return "<ProtocolError %r %r>" % (self.xmpp_name, self.message)
169
170 -class BadRequestProtocolError(ProtocolError):
171 """Raised when invalid stanza is processed and 'bad-request' error should be reported."""
172 - def __init__(self, message):
173 ProtocolError.__init__(self, "bad-request", message)
174
175 -class JIDMalformedProtocolError(ProtocolError, JIDError):
176 """Raised when invalid JID is encountered."""
177 - def __init__(self, message):
178 ProtocolError.__init__(self, "jid-malformed", message)
179
180 -class FeatureNotImplementedProtocolError(ProtocolError):
181 """Raised when stanza requests a feature which is not (yet) implemented."""
182 - def __init__(self, message):
183 ProtocolError.__init__(self, "feature-not-implemented", message)
184 185 # vi: sts=4 et sw=4 186