summaryrefslogtreecommitdiff
path: root/sleekxmpp/plugins/xep_0016/privacy.py
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/plugins/xep_0016/privacy.py
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/plugins/xep_0016/privacy.py')
-rw-r--r--sleekxmpp/plugins/xep_0016/privacy.py110
1 files changed, 110 insertions, 0 deletions
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)