From 69ddeceb491b0791d3b6ff4a5bb135c79cf490a0 Mon Sep 17 00:00:00 2001 From: Lance Stout Date: Fri, 22 Jun 2012 21:13:30 -0700 Subject: Add support for XEP-0256: Last Activity in Presence --- sleekxmpp/plugins/__init__.py | 1 + sleekxmpp/plugins/xep_0256/__init__.py | 14 +++++++ sleekxmpp/plugins/xep_0256/last_activity.py | 64 +++++++++++++++++++++++++++++ 3 files changed, 79 insertions(+) create mode 100644 sleekxmpp/plugins/xep_0256/__init__.py create mode 100644 sleekxmpp/plugins/xep_0256/last_activity.py (limited to 'sleekxmpp/plugins') diff --git a/sleekxmpp/plugins/__init__.py b/sleekxmpp/plugins/__init__.py index cc41280c..8464f0cb 100644 --- a/sleekxmpp/plugins/__init__.py +++ b/sleekxmpp/plugins/__init__.py @@ -56,5 +56,6 @@ __all__ = [ 'xep_0224', # Attention 'xep_0231', # Bits of Binary 'xep_0249', # Direct MUC Invitations + 'xep_0256', # Last Activity in Presence 'xep_0258', # Security Labels in XMPP ] diff --git a/sleekxmpp/plugins/xep_0256/__init__.py b/sleekxmpp/plugins/xep_0256/__init__.py new file mode 100644 index 00000000..cfe712b7 --- /dev/null +++ b/sleekxmpp/plugins/xep_0256/__init__.py @@ -0,0 +1,14 @@ +""" + 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_0256.last_activity import XEP_0256 + + +register_plugin(XEP_0256) diff --git a/sleekxmpp/plugins/xep_0256/last_activity.py b/sleekxmpp/plugins/xep_0256/last_activity.py new file mode 100644 index 00000000..2938868d --- /dev/null +++ b/sleekxmpp/plugins/xep_0256/last_activity.py @@ -0,0 +1,64 @@ +""" + 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. +""" + +import logging + +from sleekxmpp import Presence +from sleekxmpp.plugins import BasePlugin +from sleekxmpp.xmlstream import register_stanza_plugin + +from sleekxmpp.plugins.xep_0012 import stanza, LastActivity + + +log = logging.getLogger(__name__) + + +class XEP_0256(BasePlugin): + + name = 'xep_0256' + description = 'XEP-0256: Last Activity in Presence' + dependencies = set(['xep_0012']) + stanza = stanza + + def plugin_init(self): + self.auto_last_activity = self.config.get('auto_last_activity', False) + + register_stanza_plugin(Presence, LastActivity) + + self.xmpp.add_filter('out', self._initial_presence_activity) + self.xmpp.add_event_handler('connected', self._reset_presence_activity) + + self._initial_presence = set() + + def _reset_presence_activity(self, e): + self._initial_presence = set() + + def _initial_presence_activity(self, stanza): + if isinstance(stanza, Presence): + use_last_activity = False + + if self.auto_last_activity and stanza['show'] in ('xa', 'away'): + use_last_activity = True + + if stanza['from'] not in self._initial_presence: + self._initial_presence.add(stanza['from']) + use_last_activity = True + + if use_last_activity: + plugin = self.xmpp['xep_0012'] + try: + result = plugin.api['get_last_activity'](stanza['from'], + None, + stanza['to']) + seconds = result['last_activity']['seconds'] + except XMPPError: + seconds = None + + if seconds is not None: + stanza['last_activity']['seconds'] = seconds + return stanza -- cgit v1.2.3 From 5027d00c109ed02b79e9c985077674f6dfd42766 Mon Sep 17 00:00:00 2001 From: Lance Stout Date: Fri, 22 Jun 2012 21:25:37 -0700 Subject: Change packaging for XEP-0256 to just a single file. --- sleekxmpp/plugins/xep_0256.py | 64 +++++++++++++++++++++++++++++ sleekxmpp/plugins/xep_0256/__init__.py | 14 ------- sleekxmpp/plugins/xep_0256/last_activity.py | 64 ----------------------------- 3 files changed, 64 insertions(+), 78 deletions(-) create mode 100644 sleekxmpp/plugins/xep_0256.py delete mode 100644 sleekxmpp/plugins/xep_0256/__init__.py delete mode 100644 sleekxmpp/plugins/xep_0256/last_activity.py (limited to 'sleekxmpp/plugins') diff --git a/sleekxmpp/plugins/xep_0256.py b/sleekxmpp/plugins/xep_0256.py new file mode 100644 index 00000000..2938868d --- /dev/null +++ b/sleekxmpp/plugins/xep_0256.py @@ -0,0 +1,64 @@ +""" + 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. +""" + +import logging + +from sleekxmpp import Presence +from sleekxmpp.plugins import BasePlugin +from sleekxmpp.xmlstream import register_stanza_plugin + +from sleekxmpp.plugins.xep_0012 import stanza, LastActivity + + +log = logging.getLogger(__name__) + + +class XEP_0256(BasePlugin): + + name = 'xep_0256' + description = 'XEP-0256: Last Activity in Presence' + dependencies = set(['xep_0012']) + stanza = stanza + + def plugin_init(self): + self.auto_last_activity = self.config.get('auto_last_activity', False) + + register_stanza_plugin(Presence, LastActivity) + + self.xmpp.add_filter('out', self._initial_presence_activity) + self.xmpp.add_event_handler('connected', self._reset_presence_activity) + + self._initial_presence = set() + + def _reset_presence_activity(self, e): + self._initial_presence = set() + + def _initial_presence_activity(self, stanza): + if isinstance(stanza, Presence): + use_last_activity = False + + if self.auto_last_activity and stanza['show'] in ('xa', 'away'): + use_last_activity = True + + if stanza['from'] not in self._initial_presence: + self._initial_presence.add(stanza['from']) + use_last_activity = True + + if use_last_activity: + plugin = self.xmpp['xep_0012'] + try: + result = plugin.api['get_last_activity'](stanza['from'], + None, + stanza['to']) + seconds = result['last_activity']['seconds'] + except XMPPError: + seconds = None + + if seconds is not None: + stanza['last_activity']['seconds'] = seconds + return stanza diff --git a/sleekxmpp/plugins/xep_0256/__init__.py b/sleekxmpp/plugins/xep_0256/__init__.py deleted file mode 100644 index cfe712b7..00000000 --- a/sleekxmpp/plugins/xep_0256/__init__.py +++ /dev/null @@ -1,14 +0,0 @@ -""" - 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_0256.last_activity import XEP_0256 - - -register_plugin(XEP_0256) diff --git a/sleekxmpp/plugins/xep_0256/last_activity.py b/sleekxmpp/plugins/xep_0256/last_activity.py deleted file mode 100644 index 2938868d..00000000 --- a/sleekxmpp/plugins/xep_0256/last_activity.py +++ /dev/null @@ -1,64 +0,0 @@ -""" - 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. -""" - -import logging - -from sleekxmpp import Presence -from sleekxmpp.plugins import BasePlugin -from sleekxmpp.xmlstream import register_stanza_plugin - -from sleekxmpp.plugins.xep_0012 import stanza, LastActivity - - -log = logging.getLogger(__name__) - - -class XEP_0256(BasePlugin): - - name = 'xep_0256' - description = 'XEP-0256: Last Activity in Presence' - dependencies = set(['xep_0012']) - stanza = stanza - - def plugin_init(self): - self.auto_last_activity = self.config.get('auto_last_activity', False) - - register_stanza_plugin(Presence, LastActivity) - - self.xmpp.add_filter('out', self._initial_presence_activity) - self.xmpp.add_event_handler('connected', self._reset_presence_activity) - - self._initial_presence = set() - - def _reset_presence_activity(self, e): - self._initial_presence = set() - - def _initial_presence_activity(self, stanza): - if isinstance(stanza, Presence): - use_last_activity = False - - if self.auto_last_activity and stanza['show'] in ('xa', 'away'): - use_last_activity = True - - if stanza['from'] not in self._initial_presence: - self._initial_presence.add(stanza['from']) - use_last_activity = True - - if use_last_activity: - plugin = self.xmpp['xep_0012'] - try: - result = plugin.api['get_last_activity'](stanza['from'], - None, - stanza['to']) - seconds = result['last_activity']['seconds'] - except XMPPError: - seconds = None - - if seconds is not None: - stanza['last_activity']['seconds'] = seconds - return stanza -- cgit v1.2.3 From b11e1ee92d4c81fc3943c376477aa8be2a8aa0e6 Mon Sep 17 00:00:00 2001 From: Lance Stout Date: Fri, 22 Jun 2012 21:26:25 -0700 Subject: Add meta plugin for XEP-0270, 2010 compliance suite. Registering this plugin will load the plugins required for advanced client compliance status. --- sleekxmpp/plugins/__init__.py | 1 + sleekxmpp/plugins/xep_0270.py | 17 +++++++++++++++++ 2 files changed, 18 insertions(+) create mode 100644 sleekxmpp/plugins/xep_0270.py (limited to 'sleekxmpp/plugins') diff --git a/sleekxmpp/plugins/__init__.py b/sleekxmpp/plugins/__init__.py index 8464f0cb..5aa48a47 100644 --- a/sleekxmpp/plugins/__init__.py +++ b/sleekxmpp/plugins/__init__.py @@ -58,4 +58,5 @@ __all__ = [ 'xep_0249', # Direct MUC Invitations 'xep_0256', # Last Activity in Presence 'xep_0258', # Security Labels in XMPP + 'xep_0270', # XMPP Compliance Suites 2010 ] diff --git a/sleekxmpp/plugins/xep_0270.py b/sleekxmpp/plugins/xep_0270.py new file mode 100644 index 00000000..41ccd73b --- /dev/null +++ b/sleekxmpp/plugins/xep_0270.py @@ -0,0 +1,17 @@ +""" + 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 + + +class XEP_0270(BasePlugin): + + name = 'xep_0270' + description = 'XEP-0270: XMPP Compliance Suites 2010' + dependencies = set(['xep_0030', 'xep_0115', 'xep_0054', + 'xep_0163', 'xep_0045', 'xep_0085']) -- cgit v1.2.3 From e4911e93919e733e1a3a0c1db4c6a32b87fef04a Mon Sep 17 00:00:00 2001 From: Lance Stout Date: Fri, 22 Jun 2012 21:50:43 -0700 Subject: Add meta plugin for XEP-0302 for the 2012 compliance suite. There are still a few remaining items in the RFCs to add support for, but the current plugin support matches the advanced client profile. --- sleekxmpp/plugins/__init__.py | 1 + sleekxmpp/plugins/xep_0302.py | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+) create mode 100644 sleekxmpp/plugins/xep_0302.py (limited to 'sleekxmpp/plugins') diff --git a/sleekxmpp/plugins/__init__.py b/sleekxmpp/plugins/__init__.py index 5aa48a47..1466a274 100644 --- a/sleekxmpp/plugins/__init__.py +++ b/sleekxmpp/plugins/__init__.py @@ -59,4 +59,5 @@ __all__ = [ 'xep_0256', # Last Activity in Presence 'xep_0258', # Security Labels in XMPP 'xep_0270', # XMPP Compliance Suites 2010 + 'xep_0302', # XMPP Compliance Suites 2012 ] diff --git a/sleekxmpp/plugins/xep_0302.py b/sleekxmpp/plugins/xep_0302.py new file mode 100644 index 00000000..83ab9a35 --- /dev/null +++ b/sleekxmpp/plugins/xep_0302.py @@ -0,0 +1,18 @@ +""" + 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 + + +class XEP_0302(BasePlugin): + + name = 'xep_0302' + description = 'XEP-0302: XMPP Compliance Suites 2012' + dependencies = set(['xep_0030', 'xep_0115', 'xep_0054', + 'xep_0163', 'xep_0045', 'xep_0085', + 'xep_0184', 'xep_0198']) -- cgit v1.2.3 From c2c7cc032b38d8a7a293467a8c2ff7380cbc756f Mon Sep 17 00:00:00 2001 From: Lance Stout Date: Fri, 22 Jun 2012 21:58:50 -0700 Subject: Fix plugin registration for single file plugins. --- sleekxmpp/plugins/xep_0256.py | 5 ++++- sleekxmpp/plugins/xep_0270.py | 5 ++++- sleekxmpp/plugins/xep_0302.py | 5 ++++- 3 files changed, 12 insertions(+), 3 deletions(-) (limited to 'sleekxmpp/plugins') diff --git a/sleekxmpp/plugins/xep_0256.py b/sleekxmpp/plugins/xep_0256.py index 2938868d..265a5da8 100644 --- a/sleekxmpp/plugins/xep_0256.py +++ b/sleekxmpp/plugins/xep_0256.py @@ -9,7 +9,7 @@ import logging from sleekxmpp import Presence -from sleekxmpp.plugins import BasePlugin +from sleekxmpp.plugins import BasePlugin, register_plugin from sleekxmpp.xmlstream import register_stanza_plugin from sleekxmpp.plugins.xep_0012 import stanza, LastActivity @@ -62,3 +62,6 @@ class XEP_0256(BasePlugin): if seconds is not None: stanza['last_activity']['seconds'] = seconds return stanza + + +register_plugin(XEP_0256) diff --git a/sleekxmpp/plugins/xep_0270.py b/sleekxmpp/plugins/xep_0270.py index 41ccd73b..eadd45ad 100644 --- a/sleekxmpp/plugins/xep_0270.py +++ b/sleekxmpp/plugins/xep_0270.py @@ -6,7 +6,7 @@ See the file LICENSE for copying permission. """ -from sleekxmpp.plugins import BasePlugin +from sleekxmpp.plugins import BasePlugin, register_plugin class XEP_0270(BasePlugin): @@ -15,3 +15,6 @@ class XEP_0270(BasePlugin): description = 'XEP-0270: XMPP Compliance Suites 2010' dependencies = set(['xep_0030', 'xep_0115', 'xep_0054', 'xep_0163', 'xep_0045', 'xep_0085']) + + +register_plugin(XEP_0270) diff --git a/sleekxmpp/plugins/xep_0302.py b/sleekxmpp/plugins/xep_0302.py index 83ab9a35..dee60f91 100644 --- a/sleekxmpp/plugins/xep_0302.py +++ b/sleekxmpp/plugins/xep_0302.py @@ -6,7 +6,7 @@ See the file LICENSE for copying permission. """ -from sleekxmpp.plugins import BasePlugin +from sleekxmpp.plugins import BasePlugin, register_plugin class XEP_0302(BasePlugin): @@ -16,3 +16,6 @@ class XEP_0302(BasePlugin): dependencies = set(['xep_0030', 'xep_0115', 'xep_0054', 'xep_0163', 'xep_0045', 'xep_0085', 'xep_0184', 'xep_0198']) + + +register_plugin(XEP_0302) -- cgit v1.2.3