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
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])
34 for each in xep0106mapping:
35 str = str.replace('\\' + each[1], each[0])
36 return str.replace('\\5c', '\\')
38 if __name__ == "__main__":
39 def test(before,valid):
40 during = JIDEncode(before)
41 after = JIDDecode(during)
42 if during == valid and after == before:
43 print 'PASS Before: ' + before
44 print 'PASS During: ' + during
46 print 'FAIL Before: ' + before
47 print 'FAIL During: ' + during
48 print 'FAIL After : ' + after
51 test('jid escaping',r'jid\20escaping')
54 test(r'\2plus\2is\4',r'\2plus\2is\4')
55 test(r'foo\bar',r'foo\bar')
56 test(r'foob\41r',r'foob\41r')
57 test('here\'s_a wild_&_/cr%zy/
[email protected]',r'here\27s_a\20wild_\26_\2fcr%zy\2f_address\40example.com')