annotate idavoll/xmpp_error.py @ 14:68e900b46d49

Send service-unavailable for unknown iq child namespaces
author Ralph Meijer <ralphm@ik.nu>
date Sat, 17 Jul 2004 22:03:37 +0000
parents 226a97dd79ff
children 53b1bea9289b
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
6
76efc9114469 Code cleanup
Ralph Meijer <ralphm@ik.nu>
parents: 3
diff changeset
1 NS_XMPP_STANZAS = "urn:ietf:params:xml:ns:xmpp-stanzas"
76efc9114469 Code cleanup
Ralph Meijer <ralphm@ik.nu>
parents: 3
diff changeset
2
1
4cc41776b7d7 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
3 conditions = {
3
32e1561cd68e Added bad-request error.
Ralph Meijer <ralphm@ik.nu>
parents: 1
diff changeset
4 'bad-request': {'code': '400', 'type': 'modify'},
1
4cc41776b7d7 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
5 'not-authorized': {'code': '401', 'type': 'cancel'},
4cc41776b7d7 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
6 'item-not-found': {'code': '404', 'type': 'cancel'},
13
226a97dd79ff Added two errors
Ralph Meijer <ralphm@ik.nu>
parents: 6
diff changeset
7 'internal-server-error': {'code': '500', 'type': 'wait'},
1
4cc41776b7d7 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
8 'feature-not-implemented': {'code': '501', 'type': 'cancel'},
13
226a97dd79ff Added two errors
Ralph Meijer <ralphm@ik.nu>
parents: 6
diff changeset
9 'service-unavailable': {'code': '503', 'type': 'cancel'},
1
4cc41776b7d7 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
10 }
4cc41776b7d7 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
11
4cc41776b7d7 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
12 def error_from_iq(iq, condition, text = '', type = None):
4cc41776b7d7 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
13 iq.swapAttributeValues("to", "from")
4cc41776b7d7 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
14 iq["type"] = 'error'
4cc41776b7d7 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
15 e = iq.addElement("error")
4cc41776b7d7 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
16
6
76efc9114469 Code cleanup
Ralph Meijer <ralphm@ik.nu>
parents: 3
diff changeset
17 c = e.addElement((NS_XMPP_STANZAS, condition), NS_XMPP_STANZAS)
1
4cc41776b7d7 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
18
4cc41776b7d7 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
19 if type == None:
4cc41776b7d7 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
20 type = conditions[condition]['type']
4cc41776b7d7 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
21
4cc41776b7d7 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
22 code = conditions[condition]['code']
4cc41776b7d7 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
23
4cc41776b7d7 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
24 e["code"] = code
4cc41776b7d7 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
25 e["type"] = type
4cc41776b7d7 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
26
4cc41776b7d7 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
27 if text:
6
76efc9114469 Code cleanup
Ralph Meijer <ralphm@ik.nu>
parents: 3
diff changeset
28 t = e.addElement((NS_XMPP_STANZAS, "text"), NS_XMPP_STANZAS, text)
1
4cc41776b7d7 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
29
4cc41776b7d7 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
30 return iq