Rename to slixmpp
[slixmpp.git] / slixmpp / plugins / xep_0049 / private_storage.py
blob99a04fe93d3410352db3e3da84892197769a6821
1 """
2 Slixmpp: The Slick XMPP Library
3 Copyright (C) 2012 Nathanael C. Fritz, Lance J.T. Stout
4 This file is part of Slixmpp.
6 See the file LICENSE for copying permission.
7 """
9 import logging
11 from slixmpp import Iq
12 from slixmpp.plugins import BasePlugin
13 from slixmpp.xmlstream.handler import Callback
14 from slixmpp.xmlstream.matcher import StanzaPath
15 from slixmpp.xmlstream import register_stanza_plugin
16 from slixmpp.plugins.xep_0049 import stanza, PrivateXML
19 log = logging.getLogger(__name__)
22 class XEP_0049(BasePlugin):
24 name = 'xep_0049'
25 description = 'XEP-0049: Private XML Storage'
26 dependencies = set([])
27 stanza = stanza
29 def plugin_init(self):
30 register_stanza_plugin(Iq, PrivateXML)
32 def register(self, stanza):
33 register_stanza_plugin(PrivateXML, stanza, iterable=True)
35 def store(self, data, ifrom=None, block=True, timeout=None, callback=None):
36 iq = self.xmpp.Iq()
37 iq['type'] = 'set'
38 iq['from'] = ifrom
40 if not isinstance(data, list):
41 data = [data]
43 for elem in data:
44 iq['private'].append(elem)
46 return iq.send(block=block, timeout=timeout, callback=callback)
48 def retrieve(self, name, ifrom=None, block=True, timeout=None, callback=None):
49 iq = self.xmpp.Iq()
50 iq['type'] = 'get'
51 iq['from'] = ifrom
52 iq['private'].enable(name)
53 return iq.send(block=block, timeout=timeout, callback=callback)