summaryrefslogtreecommitdiff
path: root/sleekxmpp
diff options
context:
space:
mode:
authorLance Stout <lancestout@gmail.com>2012-07-30 22:07:24 -0700
committerLance Stout <lancestout@gmail.com>2012-07-30 22:07:24 -0700
commit7c6ef18e4f953db6bc596c3729f1e286bd7acb8d (patch)
tree7a9ee28d55ba1d3342e21a66f80331f5588f06ad /sleekxmpp
parentf8856467d523eb7674974bbbd831c43939efa845 (diff)
downloadslixmpp-7c6ef18e4f953db6bc596c3729f1e286bd7acb8d.tar.gz
slixmpp-7c6ef18e4f953db6bc596c3729f1e286bd7acb8d.tar.bz2
slixmpp-7c6ef18e4f953db6bc596c3729f1e286bd7acb8d.tar.xz
slixmpp-7c6ef18e4f953db6bc596c3729f1e286bd7acb8d.zip
Add initial support for XEP-0016 Privacy Lists
Diffstat (limited to 'sleekxmpp')
-rw-r--r--sleekxmpp/plugins/__init__.py1
-rw-r--r--sleekxmpp/plugins/xep_0016/__init__.py16
-rw-r--r--sleekxmpp/plugins/xep_0016/privacy.py110
-rw-r--r--sleekxmpp/plugins/xep_0016/stanza.py103
4 files changed, 230 insertions, 0 deletions
diff --git a/sleekxmpp/plugins/__init__.py b/sleekxmpp/plugins/__init__.py
index ce64e152..688da095 100644
--- a/sleekxmpp/plugins/__init__.py
+++ b/sleekxmpp/plugins/__init__.py
@@ -18,6 +18,7 @@ __all__ = [
'xep_0004', # Data Forms
'xep_0009', # Jabber-RPC
'xep_0012', # Last Activity
+ 'xep_0016', # Privacy Lists
'xep_0027', # Current Jabber OpenPGP Usage
'xep_0030', # Service Discovery
'xep_0033', # Extended Stanza Addresses
diff --git a/sleekxmpp/plugins/xep_0016/__init__.py b/sleekxmpp/plugins/xep_0016/__init__.py
new file mode 100644
index 00000000..06704d26
--- /dev/null
+++ b/sleekxmpp/plugins/xep_0016/__init__.py
@@ -0,0 +1,16 @@
+"""
+ 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.plugins.base import register_plugin
+
+from sleekxmpp.plugins.xep_0016 import stanza
+from sleekxmpp.plugins.xep_0016.stanza import Privacy
+from sleekxmpp.plugins.xep_0016.privacy import XEP_0016
+
+
+register_plugin(XEP_0016)
diff --git a/sleekxmpp/plugins/xep_0016/privacy.py b/sleekxmpp/plugins/xep_0016/privacy.py
new file mode 100644
index 00000000..79fd68f0
--- /dev/null
+++ b/sleekxmpp/plugins/xep_0016/privacy.py
@@ -0,0 +1,110 @@
+"""
+ SleekXMPP: The Sleek XMPP Library
+ Copyright (C) 2011 Nathanael C. Fritz, Lance J.T. Stout
+ This file is part of SleekXMPP.
+
+ See the file LICENSE for copying permission.
+"""
+
+from sleekxmpp import Iq
+from sleekxmpp.xmlstream import register_stanza_plugin
+from sleekxmpp.plugins import BasePlugin
+from sleekxmpp.plugins.xep_0016 import stanza
+from sleekxmpp.plugins.xep_0016.stanza import Privacy, Item
+
+
+class XEP_0016(BasePlugin):
+
+ name = 'xep_0016'
+ description = 'XEP-0016: Privacy Lists'
+ dependencies = set(['xep_0030'])
+ stanza = stanza
+
+ def plugin_init(self):
+ register_stanza_plugin(Iq, Privacy)
+
+ def plugin_end(self):
+ self.xmpp['xep_0030'].del_feature(feature=Privacy.namespace)
+
+ def session_bind(self, jid):
+ self.xmpp['xep_0030'].add_feature(Privacy.namespace)
+
+ def get_privacy_lists(self, block=True, timeout=None, callback=None):
+ iq = self.xmpp.Iq()
+ iq['type'] = 'get'
+ iq.enable('privacy')
+ return iq.send(block=block, timeout=timeout, callback=callback)
+
+ def get_list(self, name, block=True, timeout=None, callback=None):
+ iq = self.xmpp.Iq()
+ iq['type'] = 'get'
+ iq['privacy']['list']['name'] = name
+ return iq.send(block=block, timeout=timeout, callback=callback)
+
+ def get_active(self, block=True, timeout=None, callback=None):
+ iq = self.xmpp.Iq()
+ iq['type'] = 'get'
+ iq['privacy'].enable('active')
+ return iq.send(block=block, timeout=timeout, callback=callback)
+
+ def get_default(self, block=True, timeout=None, callback=None):
+ iq = self.xmpp.Iq()
+ iq['type'] = 'get'
+ iq['privacy'].enable('default')
+ return iq.send(block=block, timeout=timeout, callback=callback)
+
+ def activate(self, name, block=True, timeout=None, callback=None):
+ iq = self.xmpp.Iq()
+ iq['type'] = 'set'
+ iq['privacy']['active']['name'] = name
+ return iq.send(block=block, timeout=timeout, callback=callback)
+
+ def deactivate(self, block=True, timeout=None, callback=None):
+ iq = self.xmpp.Iq()
+ iq['type'] = 'set'
+ iq['privacy'].enable('active')
+ return iq.send(block=block, timeout=timeout, callback=callback)
+
+ def make_default(self, name, block=True, timeout=None, callback=None):
+ iq = self.xmpp.Iq()
+ iq['type'] = 'set'
+ iq['privacy']['default']['name'] = name
+ return iq.send(block=block, timeout=timeout, callback=callback)
+
+ def remove_default(self, block=True, timeout=None, callback=None):
+ iq = self.xmpp.Iq()
+ iq['type'] = 'set'
+ iq['privacy'].enable('default')
+ return iq.send(block=block, timeout=timeout, callback=callback)
+
+ def edit_list(self, name, rules, block=True, timeout=None, callback=None):
+ iq = self.xmpp.Iq()
+ iq['type'] = 'set'
+ iq['privacy']['list']['name'] = name
+ priv_list = iq['privacy']['list']
+
+ if not rules:
+ rules = []
+
+ for rule in rules:
+ if isinstance(rule, Item):
+ priv_list.append(rule)
+ continue
+
+ priv_list.add_item(
+ rule['value'],
+ rule['action'],
+ rule['order'],
+ itype=rule.get('type', None),
+ iq=rule.get('iq', None),
+ message=rule.get('message', None),
+ presence_in=rule.get('presence_in',
+ rule.get('presence-in', None)),
+ presence_out=rule.get('presence_out',
+ rule.get('presence-out', None)))
+
+ def remove_list(self, name, block=True, timeout=None, callback=None):
+ iq = self.xmpp.Iq()
+ iq['type'] = 'set'
+ iq['privacy']['list']['name'] = name
+ return iq.send(block=block, timeout=timeout, callback=callback)
diff --git a/sleekxmpp/plugins/xep_0016/stanza.py b/sleekxmpp/plugins/xep_0016/stanza.py
new file mode 100644
index 00000000..3f9977fc
--- /dev/null
+++ b/sleekxmpp/plugins/xep_0016/stanza.py
@@ -0,0 +1,103 @@
+from sleekxmpp.xmlstream import ET, ElementBase, register_stanza_plugin
+
+
+class Privacy(ElementBase):
+ name = 'query'
+ namespace = 'jabber:iq:privacy'
+ plugin_attrib = 'privacy'
+ interfaces = set()
+
+ def add_list(self, name):
+ priv_list = List()
+ priv_list['name'] = name
+ self.append(priv_list)
+ return priv_list
+
+
+class Active(ElementBase):
+ name = 'active'
+ namespace = 'jabber:iq:privacy'
+ plugin_attrib = name
+ interfaces = set(['name'])
+
+
+class Default(ElementBase):
+ name = 'default'
+ namespace = 'jabber:iq:privacy'
+ plugin_attrib = name
+ interfaces = set(['name'])
+
+
+class List(ElementBase):
+ name = 'list'
+ namespace = 'jabber:iq:privacy'
+ plugin_attrib = name
+ plugin_multi_attrib = 'lists'
+ interfaces = set(['name'])
+
+ def add_item(self, value, action, order, itype=None, iq=False,
+ message=False, presence_in=False, presence_out=False):
+ item = Item()
+ item.values = {'type': itype,
+ 'value': value,
+ 'action': action,
+ 'order': order,
+ 'message': message,
+ 'iq': iq,
+ 'presence_in': presence_in,
+ 'presence_out': presence_out}
+ self.append(item)
+ return item
+
+
+class Item(ElementBase):
+ name = 'item'
+ namespace = 'jabber:iq:privacy'
+ plugin_attrib = name
+ plugin_multi_attrib = 'items'
+ interfaces = set(['type', 'value', 'action', 'order', 'iq',
+ 'message', 'presence_in', 'presence_out'])
+ bool_interfaces = set(['message', 'iq', 'presence_in', 'presence_out'])
+
+ type_values = ('', 'jid', 'group', 'subscription')
+ action_values = ('allow', 'deny')
+
+ def set_type(self, value):
+ if value and value not in self.type_values:
+ raise ValueError('Unknown type value: %s' % value)
+ else:
+ self._set_attr('type', value)
+
+ def set_action(self, value):
+ if value not in self.action_values:
+ raise ValueError('Unknown action value: %s' % value)
+ else:
+ self._set_attr('action', value)
+
+ def set_presence_in(self, value):
+ keep = True if value else False
+ self._set_sub_text('presence-in', '', keep=keep)
+
+ def get_presence_in(self):
+ pres = self.xml.find('{%s}presence-in' % self.namespace)
+ return pres is not None
+
+ def del_presence_in(self):
+ self._del_sub('{%s}presence-in' % self.namespace)
+
+ def set_presence_out(self, value):
+ keep = True if value else False
+ self._set_sub_text('presence-in', '', keep=keep)
+
+ def get_presence_out(self):
+ pres = self.xml.find('{%s}presence-in' % self.namespace)
+ return pres is not None
+
+ def del_presence_out(self):
+ self._del_sub('{%s}presence-in' % self.namespace)
+
+
+register_stanza_plugin(Privacy, Active)
+register_stanza_plugin(Privacy, Default)
+register_stanza_plugin(Privacy, List, iterable=True)
+register_stanza_plugin(List, Item, iterable=True)