summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLink Mauve <linkmauve@example.com>2019-01-22 19:28:38 +0100
committerLink Mauve <linkmauve@example.com>2019-01-22 19:28:38 +0100
commitd85d8f4479190747c6344b5f718cd9d027546c56 (patch)
treec35f186c09f8fa38340b683ceb1738acf51ab147
parentfb75f7cda9e8703bd5766cd291a793f23ead28a5 (diff)
parent31f5e846711917519ee2eb84427378b6a97bf7f7 (diff)
downloadslixmpp-d85d8f4479190747c6344b5f718cd9d027546c56.tar.gz
slixmpp-d85d8f4479190747c6344b5f718cd9d027546c56.tar.bz2
slixmpp-d85d8f4479190747c6344b5f718cd9d027546c56.tar.xz
slixmpp-d85d8f4479190747c6344b5f718cd9d027546c56.zip
Merge branch 'xep-0335' into 'master'
Add xep_0335: JSON Containers See merge request poezio/slixmpp!5
-rw-r--r--slixmpp/plugins/xep_0335/__init__.py14
-rw-r--r--slixmpp/plugins/xep_0335/json_containers.py22
-rw-r--r--slixmpp/plugins/xep_0335/stanza.py28
3 files changed, 64 insertions, 0 deletions
diff --git a/slixmpp/plugins/xep_0335/__init__.py b/slixmpp/plugins/xep_0335/__init__.py
new file mode 100644
index 00000000..7bc3bddf
--- /dev/null
+++ b/slixmpp/plugins/xep_0335/__init__.py
@@ -0,0 +1,14 @@
+"""
+ Slixmpp: The Slick XMPP Library
+ Copyright (C) 2018 Maxime “pep” Buquet
+ This file is part of Slixmpp.
+
+ See the file LICENSE for copying permission.
+"""
+
+from slixmpp.plugins.base import register_plugin
+
+from slixmpp.plugins.xep_0335.stanza import JSON_Container
+from slixmpp.plugins.xep_0335.json_containers import XEP_0335
+
+register_plugin(XEP_0335)
diff --git a/slixmpp/plugins/xep_0335/json_containers.py b/slixmpp/plugins/xep_0335/json_containers.py
new file mode 100644
index 00000000..baeb5889
--- /dev/null
+++ b/slixmpp/plugins/xep_0335/json_containers.py
@@ -0,0 +1,22 @@
+"""
+ Slixmpp: The Slick XMPP Library
+ Copyright (C) 2018 Maxime “pep” Buquet
+ This file is part of Slixmpp.
+
+ See the file LICENSE for copying permission.
+"""
+
+from slixmpp import Message
+from slixmpp.plugins import BasePlugin
+from slixmpp.xmlstream import register_stanza_plugin
+from slixmpp.plugins.xep_0335 import JSON_Container
+
+
+class XEP_0335(BasePlugin):
+
+ name = 'xep_0335'
+ description = 'XEP-0335: JSON Containers'
+ stanza = stanza
+
+ def plugin_init(self):
+ register_stanza_plugin(Message, JSON_Container)
diff --git a/slixmpp/plugins/xep_0335/stanza.py b/slixmpp/plugins/xep_0335/stanza.py
new file mode 100644
index 00000000..6d5ca5b5
--- /dev/null
+++ b/slixmpp/plugins/xep_0335/stanza.py
@@ -0,0 +1,28 @@
+"""
+ Slixmpp: The Slick XMPP Library
+ Copyright (C) 2018 Maxime “pep” Buquet
+ This file is part of Slixmpp.
+
+ See the file LICENSE for copying permission.
+"""
+
+import json
+from slixmpp.xmlstream import ElementBase
+
+
+class JSON_Container(ElementBase):
+ name = 'json'
+ plugin_attrib = 'json'
+ namespace = 'urn:xmpp:json:0'
+ interfaces = {'value'}
+
+ def get_value(self):
+ return json.loads(self.xml.text)
+
+ def set_value(self, value):
+ if not isinstance(value, str):
+ value = json.dumps(value)
+ self.xml.text = value
+
+ def del_value(self):
+ self.xml.text = ''