2 Slixmpp: The Slick XMPP Library
3 Copyright (C) 2011 Nathanael C. Fritz, Lance J.T. Stout
4 This file is part of Slixmpp.
6 See the file LICENSE for copying permission.
9 from slixmpp
.stanza
import Error
10 from slixmpp
.xmlstream
import ElementBase
, ET
, register_stanza_plugin
13 class LegacyError(ElementBase
):
16 Older XMPP implementations used code based error messages, similar
17 to HTTP response codes. Since then, error condition elements have
18 been introduced. XEP-0086 provides a mapping between the new
19 condition elements and a combination of error types and the older
22 Also see <http://xmpp.org/extensions/xep-0086.html>.
24 Example legacy error stanzas:
25 <error xmlns="jabber:client" code="501" type="cancel">
26 <feature-not-implemented
27 xmlns="urn:ietf:params:xml:ns:xmpp-stanzas" />
30 <error code="402" type="auth">
32 xmlns="urn:ietf:params:xml:ns:xmpp-stanzas" />
36 error_map -- A map of error conditions to error types and
39 setup -- Overrides ElementBase.setup
40 set_condition -- Remap the type and code interfaces when a
45 namespace
= Error
.namespace
47 interfaces
= set(('condition',))
48 overrides
= ['set_condition']
50 error_map
= {'bad-request': ('modify', '400'),
51 'conflict': ('cancel', '409'),
52 'feature-not-implemented': ('cancel', '501'),
53 'forbidden': ('auth', '403'),
54 'gone': ('modify', '302'),
55 'internal-server-error': ('wait', '500'),
56 'item-not-found': ('cancel', '404'),
57 'jid-malformed': ('modify', '400'),
58 'not-acceptable': ('modify', '406'),
59 'not-allowed': ('cancel', '405'),
60 'not-authorized': ('auth', '401'),
61 'payment-required': ('auth', '402'),
62 'recipient-unavailable': ('wait', '404'),
63 'redirect': ('modify', '302'),
64 'registration-required': ('auth', '407'),
65 'remote-server-not-found': ('cancel', '404'),
66 'remote-server-timeout': ('wait', '504'),
67 'resource-constraint': ('wait', '500'),
68 'service-unavailable': ('cancel', '503'),
69 'subscription-required': ('auth', '407'),
70 'undefined-condition': (None, '500'),
71 'unexpected-request': ('wait', '400')}
74 """Don't create XML for the plugin."""
75 self
.xml
= ET
.Element('')
77 def set_condition(self
, value
):
79 Set the error type and code based on the given error
83 value -- The new error condition.
85 self
.parent().set_condition(value
)
87 error_data
= self
.error_map
.get(value
, None)
88 if error_data
is not None:
89 if error_data
[0] is not None:
90 self
.parent()['type'] = error_data
[0]
91 self
.parent()['code'] = error_data
[1]