comparison idavoll/xmpp_error.py @ 156:6250905b72f6

Fix spacing errors. Do 0.5.0 release.
author Ralph Meijer <ralphm@ik.nu>
date Mon, 28 Aug 2006 12:44:20 +0000
parents 5191ba7c4df8
children
comparison
equal deleted inserted replaced
155:5191ba7c4df8 156:6250905b72f6
2 # See LICENSE for details. 2 # See LICENSE for details.
3 3
4 NS_XMPP_STANZAS = "urn:ietf:params:xml:ns:xmpp-stanzas" 4 NS_XMPP_STANZAS = "urn:ietf:params:xml:ns:xmpp-stanzas"
5 5
6 conditions = { 6 conditions = {
7 'bad-request': {'code': '400', 'type': 'modify'}, 7 'bad-request': {'code': '400', 'type': 'modify'},
8 'not-authorized': {'code': '401', 'type': 'cancel'}, 8 'not-authorized': {'code': '401', 'type': 'cancel'},
9 'item-not-found': {'code': '404', 'type': 'cancel'}, 9 'item-not-found': {'code': '404', 'type': 'cancel'},
10 'not-acceptable': {'code': '406', 'type': 'modify'}, 10 'not-acceptable': {'code': '406', 'type': 'modify'},
11 'conflict': {'code': '409', 'type': 'cancel'}, 11 'conflict': {'code': '409', 'type': 'cancel'},
12 'internal-server-error': {'code': '500', 'type': 'wait'}, 12 'internal-server-error': {'code': '500', 'type': 'wait'},
13 'feature-not-implemented': {'code': '501', 'type': 'cancel'}, 13 'feature-not-implemented': {'code': '501', 'type': 'cancel'},
14 'service-unavailable': {'code': '503', 'type': 'cancel'}, 14 'service-unavailable': {'code': '503', 'type': 'cancel'},
15 } 15 }
16 16
17 def error_from_iq(iq, condition, text = '', type = None): 17 def error_from_iq(iq, condition, text = '', type = None):
18 iq.swapAttributeValues("to", "from") 18 iq.swapAttributeValues("to", "from")
19 iq["type"] = 'error' 19 iq["type"] = 'error'
20 e = iq.addElement("error") 20 e = iq.addElement("error")
21 21
22 c = e.addElement((NS_XMPP_STANZAS, condition), NS_XMPP_STANZAS) 22 c = e.addElement((NS_XMPP_STANZAS, condition), NS_XMPP_STANZAS)
23 23
24 if type == None: 24 if type == None:
25 type = conditions[condition]['type'] 25 type = conditions[condition]['type']
26 26
27 code = conditions[condition]['code'] 27 code = conditions[condition]['code']
28 28
29 e["code"] = code 29 e["code"] = code
30 e["type"] = type 30 e["type"] = type
31 31
32 if text: 32 if text:
33 t = e.addElement((NS_XMPP_STANZAS, "text"), NS_XMPP_STANZAS, text) 33 t = e.addElement((NS_XMPP_STANZAS, "text"), NS_XMPP_STANZAS, text)
34 34
35 return iq 35 return iq