summaryrefslogtreecommitdiff
path: root/src/xmpppy-0.5.0rc1/xmpp/jep0106.py
diff options
context:
space:
mode:
authorlouiz@4325f9fc-e183-4c21-96ce-0ab188b42d13 <louiz@4325f9fc-e183-4c21-96ce-0ab188b42d13>2010-01-31 15:09:58 +0000
committerlouiz@4325f9fc-e183-4c21-96ce-0ab188b42d13 <louiz@4325f9fc-e183-4c21-96ce-0ab188b42d13>2010-01-31 15:09:58 +0000
commitd6458b66aab2b84ff7d5a800b1e603f25181d723 (patch)
tree60a5dee7263bde102c32aa1420ee6f2d9206733e /src/xmpppy-0.5.0rc1/xmpp/jep0106.py
parent98efd30d3077e12bef459dba2dff179302116a5d (diff)
downloadpoezio-d6458b66aab2b84ff7d5a800b1e603f25181d723.tar.gz
poezio-d6458b66aab2b84ff7d5a800b1e603f25181d723.tar.bz2
poezio-d6458b66aab2b84ff7d5a800b1e603f25181d723.tar.xz
poezio-d6458b66aab2b84ff7d5a800b1e603f25181d723.zip
inclus xmppy0.5-RC1 avec les sources, sinon c'est chiant.
Diffstat (limited to 'src/xmpppy-0.5.0rc1/xmpp/jep0106.py')
-rw-r--r--src/xmpppy-0.5.0rc1/xmpp/jep0106.py57
1 files changed, 57 insertions, 0 deletions
diff --git a/src/xmpppy-0.5.0rc1/xmpp/jep0106.py b/src/xmpppy-0.5.0rc1/xmpp/jep0106.py
new file mode 100644
index 00000000..fcf11145
--- /dev/null
+++ b/src/xmpppy-0.5.0rc1/xmpp/jep0106.py
@@ -0,0 +1,57 @@
+
+# JID Escaping XEP-0106 for the xmpppy based transports written by Norman Rasmussen
+
+"""This file is the XEP-0106 commands.
+
+Implemented commands as follows:
+
+4.2 Encode : Encoding Transformation
+4.3 Decode : Decoding Transformation
+
+
+"""
+
+xep0106mapping = [
+ [' ' ,'20'],
+ ['"' ,'22'],
+ ['&' ,'26'],
+ ['\'','27'],
+ ['/' ,'2f'],
+ [':' ,'3a'],
+ ['<' ,'3c'],
+ ['>' ,'3e'],
+ ['@' ,'40']]
+
+def JIDEncode(str):
+ str = str.replace('\\5c', '\\5c5c')
+ for each in xep0106mapping:
+ str = str.replace('\\' + each[1], '\\5c' + each[1])
+ for each in xep0106mapping:
+ str = str.replace(each[0], '\\' + each[1])
+ return str
+
+def JIDDecode(str):
+ for each in xep0106mapping:
+ str = str.replace('\\' + each[1], each[0])
+ return str.replace('\\5c', '\\')
+
+if __name__ == "__main__":
+ def test(before,valid):
+ during = JIDEncode(before)
+ after = JIDDecode(during)
+ if during == valid and after == before:
+ print 'PASS Before: ' + before
+ print 'PASS During: ' + during
+ else:
+ print 'FAIL Before: ' + before
+ print 'FAIL During: ' + during
+ print 'FAIL After : ' + after
+ print
+
+ test('jid escaping',r'jid\20escaping')
+ test(r'\3and\2is\5@example.com',r'\5c3and\2is\5\40example.com')
+ test(r'\3catsand\2catsis\5cats@example.com',r'\5c3catsand\2catsis\5c5cats\40example.com')
+ test(r'\2plus\2is\4',r'\2plus\2is\4')
+ test(r'foo\bar',r'foo\bar')
+ test(r'foob\41r',r'foob\41r')
+ test('here\'s_a wild_&_/cr%zy/_address@example.com',r'here\27s_a\20wild_\26_\2fcr%zy\2f_address\40example.com')