annotate idavoll/xmpp_error.py @ 10:36f0ce354ce8

Initial revision
author Ralph Meijer <ralphm@ik.nu>
date Fri, 09 Jul 2004 15:44:23 +0000
parents 76efc9114469
children 226a97dd79ff
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'},
4cc41776b7d7 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
7 'feature-not-implemented': {'code': '501', 'type': 'cancel'},
4cc41776b7d7 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
8 }
4cc41776b7d7 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
9
4cc41776b7d7 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
10 def error_from_iq(iq, condition, text = '', type = None):
4cc41776b7d7 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
11 iq.swapAttributeValues("to", "from")
4cc41776b7d7 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
12 iq["type"] = 'error'
4cc41776b7d7 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
13 e = iq.addElement("error")
4cc41776b7d7 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
14
6
76efc9114469 Code cleanup
Ralph Meijer <ralphm@ik.nu>
parents: 3
diff changeset
15 c = e.addElement((NS_XMPP_STANZAS, condition), NS_XMPP_STANZAS)
1
4cc41776b7d7 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
16
4cc41776b7d7 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
17 if type == None:
4cc41776b7d7 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
18 type = conditions[condition]['type']
4cc41776b7d7 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
19
4cc41776b7d7 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
20 code = conditions[condition]['code']
4cc41776b7d7 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
21
4cc41776b7d7 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
22 e["code"] = code
4cc41776b7d7 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
23 e["type"] = type
4cc41776b7d7 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
24
4cc41776b7d7 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
25 if text:
6
76efc9114469 Code cleanup
Ralph Meijer <ralphm@ik.nu>
parents: 3
diff changeset
26 t = e.addElement((NS_XMPP_STANZAS, "text"), NS_XMPP_STANZAS, text)
1
4cc41776b7d7 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
27
4cc41776b7d7 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
28 return iq