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