annotate idavoll/xmpp_error.py @ 3:32e1561cd68e

Added bad-request error.
author Ralph Meijer <ralphm@ik.nu>
date Sun, 27 Jun 2004 14:05:18 +0000
parents 4cc41776b7d7
children 76efc9114469
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1
4cc41776b7d7 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
1 conditions = {
3
32e1561cd68e Added bad-request error.
Ralph Meijer <ralphm@ik.nu>
parents: 1
diff changeset
2 'bad-request': {'code': '400', 'type': 'modify'},
1
4cc41776b7d7 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
3 'not-authorized': {'code': '401', 'type': 'cancel'},
4cc41776b7d7 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
4 'item-not-found': {'code': '404', 'type': 'cancel'},
4cc41776b7d7 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
5 'feature-not-implemented': {'code': '501', 'type': 'cancel'},
4cc41776b7d7 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
6 }
4cc41776b7d7 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
7
4cc41776b7d7 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
8 def error_from_iq(iq, condition, text = '', type = None):
4cc41776b7d7 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
9 iq.swapAttributeValues("to", "from")
4cc41776b7d7 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
10 iq["type"] = 'error'
4cc41776b7d7 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
11 e = iq.addElement("error")
4cc41776b7d7 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
12
4cc41776b7d7 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
13 c = e.addElement(condition)
4cc41776b7d7 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
14 c["xmlns"] = "urn:ietf:params:xml:ns:xmpp-stanzas"
4cc41776b7d7 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
15
4cc41776b7d7 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
16 if type == None:
4cc41776b7d7 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
17 type = conditions[condition]['type']
4cc41776b7d7 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
18
4cc41776b7d7 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
19 code = conditions[condition]['code']
4cc41776b7d7 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
20
4cc41776b7d7 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
21 e["code"] = code
4cc41776b7d7 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
22 e["type"] = type
4cc41776b7d7 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
23
4cc41776b7d7 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
24 if text:
4cc41776b7d7 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
25 t = e.addElement("text", None, text)
4cc41776b7d7 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
26 t["xmlns"] = "urn:ietf:params:xml:ns:xmpp-stanzas"
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