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