1
|
1 conditions = { |
3
|
2 'bad-request': {'code': '400', 'type': 'modify'}, |
1
|
3 'not-authorized': {'code': '401', 'type': 'cancel'}, |
|
4 'item-not-found': {'code': '404', 'type': 'cancel'}, |
|
5 'feature-not-implemented': {'code': '501', 'type': 'cancel'}, |
|
6 } |
|
7 |
|
8 def error_from_iq(iq, condition, text = '', type = None): |
|
9 iq.swapAttributeValues("to", "from") |
|
10 iq["type"] = 'error' |
|
11 e = iq.addElement("error") |
|
12 |
|
13 c = e.addElement(condition) |
|
14 c["xmlns"] = "urn:ietf:params:xml:ns:xmpp-stanzas" |
|
15 |
|
16 if type == None: |
|
17 type = conditions[condition]['type'] |
|
18 |
|
19 code = conditions[condition]['code'] |
|
20 |
|
21 e["code"] = code |
|
22 e["type"] = type |
|
23 |
|
24 if text: |
|
25 t = e.addElement("text", None, text) |
|
26 t["xmlns"] = "urn:ietf:params:xml:ns:xmpp-stanzas" |
|
27 |
|
28 return iq |