diff options
author | Lance Stout <lancestout@gmail.com> | 2013-01-04 00:26:18 -0800 |
---|---|---|
committer | Lance Stout <lancestout@gmail.com> | 2013-01-04 00:32:14 -0800 |
commit | 6c0afb87b919f1f0321146323e917480851b2d63 (patch) | |
tree | 2020be8fda495b16595e28d4c357c0921ae8e807 /sleekxmpp/plugins/xep_0048/stanza.py | |
parent | e5750b368e1c158a610cea95c541b3f64bdee4b0 (diff) | |
download | slixmpp-6c0afb87b919f1f0321146323e917480851b2d63.tar.gz slixmpp-6c0afb87b919f1f0321146323e917480851b2d63.tar.bz2 slixmpp-6c0afb87b919f1f0321146323e917480851b2d63.tar.xz slixmpp-6c0afb87b919f1f0321146323e917480851b2d63.zip |
Add XEP-0048 support
Diffstat (limited to 'sleekxmpp/plugins/xep_0048/stanza.py')
-rw-r--r-- | sleekxmpp/plugins/xep_0048/stanza.py | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/sleekxmpp/plugins/xep_0048/stanza.py b/sleekxmpp/plugins/xep_0048/stanza.py new file mode 100644 index 00000000..2e30eb6a --- /dev/null +++ b/sleekxmpp/plugins/xep_0048/stanza.py @@ -0,0 +1,65 @@ +""" + SleekXMPP: The Sleek XMPP Library + Copyright (C) 2012 Nathanael C. Fritz, Lance J.T. Stout + This file is part of SleekXMPP. + + See the file LICENSE for copying permission. +""" + +from sleekxmpp.xmlstream import ET, ElementBase, register_stanza_plugin + + +class Bookmarks(ElementBase): + name = 'storage' + namespace = 'storage:bookmarks' + plugin_attrib = 'bookmarks' + interfaces = set() + + def add_conference(self, jid, nick, name=None, autojoin=None, password=None): + conf = Conference() + conf['jid'] = jid + conf['nick'] = nick + if name is None: + name = jid + conf['name'] = name + conf['autojoin'] = autojoin + conf['password'] = password + self.append(conf) + + def add_url(self, url, name=None): + saved_url = URL() + saved_url['url'] = url + if name is None: + name = url + saved_url['name'] = name + self.append(saved_url) + + +class Conference(ElementBase): + name = 'conference' + namespace = 'storage:bookmarks' + plugin_attrib = 'conference' + plugin_multi_attrib = 'conferences' + interfaces = set(['nick', 'password', 'autojoin', 'jid', 'name']) + sub_interfaces = set(['nick', 'password']) + + def get_autojoin(self): + value = self._get_attr('autojoin') + return value in ('1', 'true') + + def set_autojoin(self, value): + del self['autojoin'] + if value in ('1', 'true', True): + self._set_sub_text('autojoin', 'true') + + +class URL(ElementBase): + name = 'url' + namespace = 'storage:bookmarks' + plugin_attrib = 'url' + plugin_multi_attrib = 'urls' + interfaces = set(['url', 'name']) + + +register_stanza_plugin(Bookmarks, Conference, iterable=True) +register_stanza_plugin(Bookmarks, URL, iterable=True) |