Merge pull request #21 from geekmug/patch-1
[pyTivo/wmcbrine.git] / xmpp / jep0106.py
blob60e3d2326852bbe47dee2963864d29aee7286199
2 # JID Escaping XEP-0106 for the xmpppy based transports written by Norman Rasmussen
4 """This file is the XEP-0106 commands.
6 Implemented commands as follows:
8 4.2 Encode : Encoding Transformation
9 4.3 Decode : Decoding Transformation
12 """
14 xep0106mapping = [
15 [' ' ,'20'],
16 ['"' ,'22'],
17 ['&' ,'26'],
18 ['\'','27'],
19 ['/' ,'2f'],
20 [':' ,'3a'],
21 ['<' ,'3c'],
22 ['>' ,'3e'],
23 ['@' ,'40']]
25 def JIDEncode(str):
26 str = str.replace('\\5c', '\\5c5c')
27 for each in xep0106mapping:
28 str = str.replace('\\' + each[1], '\\5c' + each[1])
29 for each in xep0106mapping:
30 str = str.replace(each[0], '\\' + each[1])
31 return str
33 def JIDDecode(str):
34 for each in xep0106mapping:
35 str = str.replace('\\' + each[1], each[0])
36 return str.replace('\\5c', '\\')