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'}, |
19
|
7 'not-acceptable': {'code': '406', 'type': 'modify'}, |
|
8 'conflict': {'code': '409', 'type': 'cancel'}, |
13
|
9 'internal-server-error': {'code': '500', 'type': 'wait'}, |
1
|
10 'feature-not-implemented': {'code': '501', 'type': 'cancel'}, |
13
|
11 'service-unavailable': {'code': '503', 'type': 'cancel'}, |
1
|
12 } |
|
13 |
|
14 def error_from_iq(iq, condition, text = '', type = None): |
|
15 iq.swapAttributeValues("to", "from") |
|
16 iq["type"] = 'error' |
|
17 e = iq.addElement("error") |
|
18 |
6
|
19 c = e.addElement((NS_XMPP_STANZAS, condition), NS_XMPP_STANZAS) |
1
|
20 |
|
21 if type == None: |
|
22 type = conditions[condition]['type'] |
|
23 |
|
24 code = conditions[condition]['code'] |
|
25 |
|
26 e["code"] = code |
|
27 e["type"] = type |
|
28 |
|
29 if text: |
6
|
30 t = e.addElement((NS_XMPP_STANZAS, "text"), NS_XMPP_STANZAS, text) |
1
|
31 |
|
32 return iq |