root/jep0106.py

Revision 1, 0.7 kB (checked in by davux, 2 years ago)

First import to subversion.

Line 
1
2# JID Escaping XEP-0106 for the xmpppy based transports written by Norman Rasmussen
3
4"""This file is the XEP-0106 commands.
5
6Implemented commands as follows:
7
84.2 Encode : Encoding Transformation
94.3 Decode : Decoding Transformation
10
11
12"""
13
14xep0106mapping = [
15        [' ' ,'20'],
16        ['"' ,'22'],
17        ['&' ,'26'],
18        ['\'','27'],
19        ['/' ,'2f'],
20        [':' ,'3a'],
21        ['<' ,'3c'],
22        ['>' ,'3e'],
23        ['@' ,'40']]
24
25def 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
32   
33def JIDDecode(str):
34        for each in xep0106mapping:
35                str = str.replace('\\' + each[1], each[0])
36        return str.replace('\\5c', '\\')
Note: See TracBrowser for help on using the browser.