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