summaryrefslogtreecommitdiff
path: root/slixmpp/plugins/xep_0049
diff options
context:
space:
mode:
Diffstat (limited to 'slixmpp/plugins/xep_0049')
-rw-r--r--slixmpp/plugins/xep_0049/__init__.py15
-rw-r--r--slixmpp/plugins/xep_0049/private_storage.py57
-rw-r--r--slixmpp/plugins/xep_0049/stanza.py17
3 files changed, 89 insertions, 0 deletions
diff --git a/slixmpp/plugins/xep_0049/__init__.py b/slixmpp/plugins/xep_0049/__init__.py
new file mode 100644
index 00000000..396be75d
--- /dev/null
+++ b/slixmpp/plugins/xep_0049/__init__.py
@@ -0,0 +1,15 @@
+"""
+ Slixmpp: The Slick XMPP Library
+ Copyright (C) 2012 Nathanael C. Fritz, Lance J.T. Stout
+ This file is part of Slixmpp.
+
+ See the file LICENSE for copying permission.
+"""
+
+from slixmpp.plugins.base import register_plugin
+
+from slixmpp.plugins.xep_0049.stanza import PrivateXML
+from slixmpp.plugins.xep_0049.private_storage import XEP_0049
+
+
+register_plugin(XEP_0049)
diff --git a/slixmpp/plugins/xep_0049/private_storage.py b/slixmpp/plugins/xep_0049/private_storage.py
new file mode 100644
index 00000000..a66c05d1
--- /dev/null
+++ b/slixmpp/plugins/xep_0049/private_storage.py
@@ -0,0 +1,57 @@
+"""
+ Slixmpp: The Slick XMPP Library
+ Copyright (C) 2012 Nathanael C. Fritz, Lance J.T. Stout
+ This file is part of Slixmpp.
+
+ See the file LICENSE for copying permission.
+"""
+
+import logging
+
+from slixmpp import Iq
+from slixmpp.plugins import BasePlugin
+from slixmpp.xmlstream.handler import Callback
+from slixmpp.xmlstream.matcher import StanzaPath
+from slixmpp.xmlstream import register_stanza_plugin
+from slixmpp.plugins.xep_0049 import stanza, PrivateXML
+
+
+log = logging.getLogger(__name__)
+
+
+class XEP_0049(BasePlugin):
+
+ name = 'xep_0049'
+ description = 'XEP-0049: Private XML Storage'
+ dependencies = set([])
+ stanza = stanza
+
+ def plugin_init(self):
+ register_stanza_plugin(Iq, PrivateXML)
+
+ def register(self, stanza):
+ register_stanza_plugin(PrivateXML, stanza, iterable=True)
+
+ def store(self, data, ifrom=None, timeout=None, callback=None,
+ timeout_callback=None):
+ iq = self.xmpp.Iq()
+ iq['type'] = 'set'
+ iq['from'] = ifrom
+
+ if not isinstance(data, list):
+ data = [data]
+
+ for elem in data:
+ iq['private'].append(elem)
+
+ return iq.send(timeout=timeout, callback=callback,
+ timeout_callback=timeout_callback)
+
+ def retrieve(self, name, ifrom=None, timeout=None, callback=None,
+ timeout_callback=None):
+ iq = self.xmpp.Iq()
+ iq['type'] = 'get'
+ iq['from'] = ifrom
+ iq['private'].enable(name)
+ return iq.send(timeout=timeout, callback=callback,
+ timeout_callback=timeout_callback)
diff --git a/slixmpp/plugins/xep_0049/stanza.py b/slixmpp/plugins/xep_0049/stanza.py
new file mode 100644
index 00000000..a8d425ba
--- /dev/null
+++ b/slixmpp/plugins/xep_0049/stanza.py
@@ -0,0 +1,17 @@
+"""
+ Slixmpp: The Slick XMPP Library
+ Copyright (C) 2012 Nathanael C. Fritz, Lance J.T. Stout
+ This file is part of Slixmpp.
+
+ See the file LICENSE for copying permission.
+"""
+
+from slixmpp.xmlstream import ET, ElementBase
+
+
+class PrivateXML(ElementBase):
+
+ name = 'query'
+ namespace = 'jabber:iq:private'
+ plugin_attrib = 'private'
+ interfaces = set()