diff options
author | Lance Stout <lancestout@gmail.com> | 2012-07-31 21:33:19 -0700 |
---|---|---|
committer | Lance Stout <lancestout@gmail.com> | 2012-07-31 21:33:19 -0700 |
commit | 06a9d9fc3075df8e07960716c25d1eca2eb47f05 (patch) | |
tree | 94adfe3467fb50e3710548d6c97f1a6b36ed57a8 /sleekxmpp/plugins | |
parent | 44ce01a70b7926a1e1f4af6692be3bdc671f7318 (diff) | |
parent | 1383ca19b50ae7463a1f310f007ed120f811b574 (diff) | |
download | slixmpp-06a9d9fc3075df8e07960716c25d1eca2eb47f05.tar.gz slixmpp-06a9d9fc3075df8e07960716c25d1eca2eb47f05.tar.bz2 slixmpp-06a9d9fc3075df8e07960716c25d1eca2eb47f05.tar.xz slixmpp-06a9d9fc3075df8e07960716c25d1eca2eb47f05.zip |
Merge branch 'master' into develop
Conflicts:
sleekxmpp/thirdparty/__init__.py
Diffstat (limited to 'sleekxmpp/plugins')
-rw-r--r-- | sleekxmpp/plugins/__init__.py | 2 | ||||
-rw-r--r-- | sleekxmpp/plugins/xep_0016/__init__.py | 16 | ||||
-rw-r--r-- | sleekxmpp/plugins/xep_0016/privacy.py | 110 | ||||
-rw-r--r-- | sleekxmpp/plugins/xep_0016/stanza.py | 103 | ||||
-rw-r--r-- | sleekxmpp/plugins/xep_0047/stanza.py | 2 | ||||
-rw-r--r-- | sleekxmpp/plugins/xep_0050/adhoc.py | 6 | ||||
-rw-r--r-- | sleekxmpp/plugins/xep_0054/stanza.py | 3 | ||||
-rw-r--r-- | sleekxmpp/plugins/xep_0084/stanza.py | 2 | ||||
-rw-r--r-- | sleekxmpp/plugins/xep_0242.py | 21 | ||||
-rw-r--r-- | sleekxmpp/plugins/xep_0258/stanza.py | 3 |
10 files changed, 256 insertions, 12 deletions
diff --git a/sleekxmpp/plugins/__init__.py b/sleekxmpp/plugins/__init__.py index 15e8cb25..1db5a9e0 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 @@ -60,6 +61,7 @@ __all__ = [ 'xep_0223', # Persistent Storage of Private Data via Pubsub 'xep_0224', # Attention 'xep_0231', # Bits of Binary + 'xep_0242', # XMPP Client Compliance 2009 'xep_0249', # Direct MUC Invitations 'xep_0256', # Last Activity in Presence 'xep_0258', # Security Labels in XMPP 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) diff --git a/sleekxmpp/plugins/xep_0047/stanza.py b/sleekxmpp/plugins/xep_0047/stanza.py index afba07a8..e4a32f87 100644 --- a/sleekxmpp/plugins/xep_0047/stanza.py +++ b/sleekxmpp/plugins/xep_0047/stanza.py @@ -1,9 +1,9 @@ import re import base64 +from sleekxmpp.util import bytes from sleekxmpp.exceptions import XMPPError from sleekxmpp.xmlstream import ElementBase -from sleekxmpp.thirdparty.suelta.util import bytes VALID_B64 = re.compile(r'[A-Za-z0-9\+\/]*=*') diff --git a/sleekxmpp/plugins/xep_0050/adhoc.py b/sleekxmpp/plugins/xep_0050/adhoc.py index 032b987a..90256228 100644 --- a/sleekxmpp/plugins/xep_0050/adhoc.py +++ b/sleekxmpp/plugins/xep_0050/adhoc.py @@ -187,12 +187,6 @@ class XEP_0050(BasePlugin): jid = JID(jid) item_jid = jid.full - # Client disco uses only the bare JID - if self.xmpp.is_component: - jid = jid.full - else: - jid = jid.bare - self.xmpp['xep_0030'].add_identity(category='automation', itype='command-list', name='Ad-Hoc commands', diff --git a/sleekxmpp/plugins/xep_0054/stanza.py b/sleekxmpp/plugins/xep_0054/stanza.py index 75b69d3e..512e1dd8 100644 --- a/sleekxmpp/plugins/xep_0054/stanza.py +++ b/sleekxmpp/plugins/xep_0054/stanza.py @@ -1,8 +1,7 @@ import base64 import datetime as dt -from sleekxmpp.thirdparty.suelta.util import bytes - +from sleekxmpp.util import bytes from sleekxmpp.xmlstream import ElementBase, ET, register_stanza_plugin, JID from sleekxmpp.plugins import xep_0082 diff --git a/sleekxmpp/plugins/xep_0084/stanza.py b/sleekxmpp/plugins/xep_0084/stanza.py index e9133998..22f11b72 100644 --- a/sleekxmpp/plugins/xep_0084/stanza.py +++ b/sleekxmpp/plugins/xep_0084/stanza.py @@ -7,8 +7,8 @@ """ from base64 import b64encode, b64decode -from sleekxmpp.thirdparty.suelta.util import bytes +from sleekxmpp.util import bytes from sleekxmpp.xmlstream import ET, ElementBase, register_stanza_plugin diff --git a/sleekxmpp/plugins/xep_0242.py b/sleekxmpp/plugins/xep_0242.py new file mode 100644 index 00000000..c1bada27 --- /dev/null +++ b/sleekxmpp/plugins/xep_0242.py @@ -0,0 +1,21 @@ +""" + 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 import BasePlugin, register_plugin + + +class XEP_0242(BasePlugin): + + name = 'xep_0242' + description = 'XEP-0242: XMPP Client Compliance 2009' + dependencies = set(['xep_0030', 'xep_0115', 'xep_0054', + 'xep_0045', 'xep_0085', 'xep_0016', + 'xep_0191']) + + +register_plugin(XEP_0242) diff --git a/sleekxmpp/plugins/xep_0258/stanza.py b/sleekxmpp/plugins/xep_0258/stanza.py index 4d828a46..a506064b 100644 --- a/sleekxmpp/plugins/xep_0258/stanza.py +++ b/sleekxmpp/plugins/xep_0258/stanza.py @@ -8,8 +8,7 @@ from base64 import b64encode, b64decode -from sleekxmpp.thirdparty.suelta.util import bytes - +from sleekxmpp.util import bytes from sleekxmpp.xmlstream import ElementBase, ET, register_stanza_plugin |