From a1b33da9ca7eb0d93c02b842935386d9286d82be Mon Sep 17 00:00:00 2001 From: Lance Stout Date: Thu, 24 Jan 2013 23:05:05 -0800 Subject: Refactor Google GTalk extensions into a single meta plugin. --- sleekxmpp/plugins/gmail/__init__.py | 15 --- sleekxmpp/plugins/gmail/notifications.py | 77 --------------- sleekxmpp/plugins/gmail/stanza.py | 101 ------------------- sleekxmpp/plugins/google/__init__.py | 47 +++++++++ sleekxmpp/plugins/google/auth/__init__.py | 10 ++ sleekxmpp/plugins/google/auth/auth.py | 52 ++++++++++ sleekxmpp/plugins/google/auth/stanza.py | 49 +++++++++ sleekxmpp/plugins/google/gmail/__init__.py | 10 ++ sleekxmpp/plugins/google/gmail/notifications.py | 77 +++++++++++++++ sleekxmpp/plugins/google/gmail/stanza.py | 101 +++++++++++++++++++ sleekxmpp/plugins/google/nosave/__init__.py | 10 ++ sleekxmpp/plugins/google/nosave/nosave.py | 83 ++++++++++++++++ sleekxmpp/plugins/google/nosave/stanza.py | 59 +++++++++++ sleekxmpp/plugins/google/settings/__init__.py | 10 ++ sleekxmpp/plugins/google/settings/settings.py | 65 ++++++++++++ sleekxmpp/plugins/google/settings/stanza.py | 110 +++++++++++++++++++++ .../plugins/google_domain_discovery/__init__.py | 15 --- sleekxmpp/plugins/google_domain_discovery/auth.py | 49 --------- .../plugins/google_domain_discovery/stanza.py | 35 ------- sleekxmpp/plugins/google_nosave/__init__.py | 15 --- sleekxmpp/plugins/google_nosave/nosave.py | 83 ---------------- sleekxmpp/plugins/google_nosave/stanza.py | 59 ----------- sleekxmpp/plugins/google_settings/__init__.py | 15 --- sleekxmpp/plugins/google_settings/settings.py | 68 ------------- sleekxmpp/plugins/google_settings/stanza.py | 110 --------------------- 25 files changed, 683 insertions(+), 642 deletions(-) delete mode 100644 sleekxmpp/plugins/gmail/__init__.py delete mode 100644 sleekxmpp/plugins/gmail/notifications.py delete mode 100644 sleekxmpp/plugins/gmail/stanza.py create mode 100644 sleekxmpp/plugins/google/__init__.py create mode 100644 sleekxmpp/plugins/google/auth/__init__.py create mode 100644 sleekxmpp/plugins/google/auth/auth.py create mode 100644 sleekxmpp/plugins/google/auth/stanza.py create mode 100644 sleekxmpp/plugins/google/gmail/__init__.py create mode 100644 sleekxmpp/plugins/google/gmail/notifications.py create mode 100644 sleekxmpp/plugins/google/gmail/stanza.py create mode 100644 sleekxmpp/plugins/google/nosave/__init__.py create mode 100644 sleekxmpp/plugins/google/nosave/nosave.py create mode 100644 sleekxmpp/plugins/google/nosave/stanza.py create mode 100644 sleekxmpp/plugins/google/settings/__init__.py create mode 100644 sleekxmpp/plugins/google/settings/settings.py create mode 100644 sleekxmpp/plugins/google/settings/stanza.py delete mode 100644 sleekxmpp/plugins/google_domain_discovery/__init__.py delete mode 100644 sleekxmpp/plugins/google_domain_discovery/auth.py delete mode 100644 sleekxmpp/plugins/google_domain_discovery/stanza.py delete mode 100644 sleekxmpp/plugins/google_nosave/__init__.py delete mode 100644 sleekxmpp/plugins/google_nosave/nosave.py delete mode 100644 sleekxmpp/plugins/google_nosave/stanza.py delete mode 100644 sleekxmpp/plugins/google_settings/__init__.py delete mode 100644 sleekxmpp/plugins/google_settings/settings.py delete mode 100644 sleekxmpp/plugins/google_settings/stanza.py diff --git a/sleekxmpp/plugins/gmail/__init__.py b/sleekxmpp/plugins/gmail/__init__.py deleted file mode 100644 index a87c78bb..00000000 --- a/sleekxmpp/plugins/gmail/__init__.py +++ /dev/null @@ -1,15 +0,0 @@ -""" - SleekXMPP: The Sleek XMPP Library - Copyright (C) 2013 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.gmail import stanza -from sleekxmpp.plugins.gmail.notifications import Gmail - - -register_plugin(Gmail) diff --git a/sleekxmpp/plugins/gmail/notifications.py b/sleekxmpp/plugins/gmail/notifications.py deleted file mode 100644 index dbc68162..00000000 --- a/sleekxmpp/plugins/gmail/notifications.py +++ /dev/null @@ -1,77 +0,0 @@ -""" - SleekXMPP: The Sleek XMPP Library - Copyright (C) 2013 Nathanael C. Fritz, Lance J.T. Stout - This file is part of SleekXMPP. - - See the file LICENSE for copying permission. -""" - -import logging - -from sleekxmpp.stanza import Iq -from sleekxmpp.xmlstream.handler import Callback -from sleekxmpp.xmlstream.matcher import MatchXPath -from sleekxmpp.xmlstream import register_stanza_plugin -from sleekxmpp.plugins import BasePlugin -from sleekxmpp.plugins.gmail import stanza - - -log = logging.getLogger(__name__) - - -class Gmail(BasePlugin): - - """ - Google: Gmail Notifications - - Also see . - """ - - name = 'gmail' - description = 'Google: Gmail Notifications' - dependencies = set() - stanza = stanza - - def plugin_init(self): - register_stanza_plugin(Iq, stanza.GmailQuery) - register_stanza_plugin(Iq, stanza.MailBox) - register_stanza_plugin(Iq, stanza.NewMail) - - self.xmpp.register_handler( - Callback('Gmail New Mail', - MatchXPath('{%s}iq/{%s}%s' % ( - self.xmpp.default_ns, - stanza.NewMail.namespace, - stanza.NewMail.name)), - self._handle_new_mail)) - - self._last_result_time = None - - def plugin_end(self): - self.xmpp.remove_handler('Gmail New Mail') - - def _handle_new_mail(self, iq): - log.info("Gmail: New email!") - iq.reply().send() - self.xmpp.event('gmail_notification') - - def check(self, block=True, timeout=None, callback=None): - last_time = self._last_result_time - self._last_result_time = str(int(time.time() * 1000)) - return self.search(newer=last_time, - block=block, - timeout=timeout, - callback=callback) - - def search(self, query=None, newer=None, block=True, - timeout=None, callback=None): - if not query: - log.info('Gmail: Checking for new email') - else: - log.info('Gmail: Searching for emails matching: "%s"', query) - iq = self.xmpp.Iq() - iq['type'] = 'get' - iq['to'] = self.xmpp.boundjid.bare - iq['gmail']['search'] = query - iq['gmail']['newer_than_time'] = newer - return iq.send(block=block, timeout=timeout, callback=callback) diff --git a/sleekxmpp/plugins/gmail/stanza.py b/sleekxmpp/plugins/gmail/stanza.py deleted file mode 100644 index e7e308e1..00000000 --- a/sleekxmpp/plugins/gmail/stanza.py +++ /dev/null @@ -1,101 +0,0 @@ -""" - SleekXMPP: The Sleek XMPP Library - Copyright (C) 2013 Nathanael C. Fritz, Lance J.T. Stout - This file is part of SleekXMPP. - - See the file LICENSE for copying permission. -""" - -from sleekxmpp.xmlstream import ElementBase, register_stanza_plugin - - -class GmailQuery(ElementBase): - namespace = 'google:mail:notify' - name = 'query' - plugin_attrib = 'gmail' - interfaces = set(['newer_than_time', 'newer_than_tid', 'search']) - - def get_search(self): - return self._get_attr('q', '') - - def set_search(self, search): - self._set_attr('q', search) - - def del_search(self): - self._del_attr('q') - - def get_newer_than_time(self): - return self._get_attr('newer-than-time', '') - - def set_newer_than_time(self, value): - self._set_attr('newer-than-time', value) - - def del_newer_than_time(self): - self._del_attr('newer-than-time') - - def get_newer_than_tid(self): - return self._get_attr('newer-than-tid', '') - - def set_newer_than_tid(self, value): - self._set_attr('newer-than-tid', value) - - def del_newer_than_tid(self): - self._del_attr('newer-than-tid') - - -class MailBox(ElementBase): - namespace = 'google:mail:notify' - name = 'mailbox' - plugin_attrib = 'gmail_messages' - interfaces = set(['result_time', 'url', 'matched', 'estimate']) - - def get_matched(self): - return self._get_attr('total-matched', '') - - def get_estimate(self): - return self._get_attr('total-estimate', '') == '1' - - def get_result_time(self): - return self._get_attr('result-time', '') - - -class MailThread(ElementBase): - namespace = 'google:mail:notify' - name = 'mail-thread-info' - plugin_attrib = 'thread' - plugin_multi_attrib = 'threads' - interfaces = set(['tid', 'participation', 'messages', 'date', - 'senders', 'url', 'labels', 'subject', 'snippet']) - sub_interfaces = set(['labels', 'subject', 'snippet']) - - def get_senders(self): - result = [] - senders = self.xml.findall('{%s}senders/{%s}sender' % ( - self.namespace, self.namespace)) - - for sender in senders: - result.append(MailSender(xml=sender)) - - return result - - -class MailSender(ElementBase): - namespace = 'google:mail:notify' - name = 'sender' - plugin_attrib = name - interfaces = set(['address', 'name', 'originator', 'unread']) - - def get_originator(self): - return self.xml.attrib.get('originator', '0') == '1' - - def get_unread(self): - return self.xml.attrib.get('unread', '0') == '1' - - -class NewMail(ElementBase): - namespace = 'google:mail:notify' - name = 'new-mail' - plugin_attrib = 'gmail_notification' - - -register_stanza_plugin(MailBox, MailThread, iterable=True) diff --git a/sleekxmpp/plugins/google/__init__.py b/sleekxmpp/plugins/google/__init__.py new file mode 100644 index 00000000..bd7ca123 --- /dev/null +++ b/sleekxmpp/plugins/google/__init__.py @@ -0,0 +1,47 @@ +""" + SleekXMPP: The Sleek XMPP Library + Copyright (C) 2013 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, BasePlugin + +from sleekxmpp.plugins.google.gmail import Gmail +from sleekxmpp.plugins.google.auth import GoogleAuth +from sleekxmpp.plugins.google.settings import GoogleSettings +from sleekxmpp.plugins.google.nosave import GoogleNoSave + + +class Google(BasePlugin): + + """ + Google: Custom GTalk Features + + Also see: + """ + + name = 'google' + description = 'Google: Custom GTalk Features' + dependencies = set([ + 'gmail', + 'google_settings', + 'google_nosave', + 'google_auth' + ]) + + def __getitem__(self, attr): + if attr in ('settings', 'nosave', 'auth'): + return self.xmpp['google_%s' % attr] + elif attr == 'gmail': + return self.xmpp['gmail'] + else: + raise KeyError(attr) + + +register_plugin(Gmail) +register_plugin(GoogleAuth) +register_plugin(GoogleSettings) +register_plugin(GoogleNoSave) +register_plugin(Google) diff --git a/sleekxmpp/plugins/google/auth/__init__.py b/sleekxmpp/plugins/google/auth/__init__.py new file mode 100644 index 00000000..5a8feb0d --- /dev/null +++ b/sleekxmpp/plugins/google/auth/__init__.py @@ -0,0 +1,10 @@ +""" + SleekXMPP: The Sleek XMPP Library + Copyright (C) 2013 Nathanael C. Fritz, Lance J.T. Stout + This file is part of SleekXMPP. + + See the file LICENSE for copying permission. +""" + +from sleekxmpp.plugins.google.auth import stanza +from sleekxmpp.plugins.google.auth.auth import GoogleAuth diff --git a/sleekxmpp/plugins/google/auth/auth.py b/sleekxmpp/plugins/google/auth/auth.py new file mode 100644 index 00000000..042bd404 --- /dev/null +++ b/sleekxmpp/plugins/google/auth/auth.py @@ -0,0 +1,52 @@ +""" + SleekXMPP: The Sleek XMPP Library + Copyright (C) 2013 Nathanael C. Fritz, Lance J.T. Stout + This file is part of SleekXMPP. + + See the file LICENSE for copying permission. +""" + +import logging + +from sleekxmpp.xmlstream import register_stanza_plugin +from sleekxmpp.plugins import BasePlugin +from sleekxmpp.plugins.google.auth import stanza + + +log = logging.getLogger(__name__) + + +class GoogleAuth(BasePlugin): + + """ + Google: Auth Extensions (JID Domain Discovery, OAuth2) + + Also see: + + + """ + + name = 'google_auth' + description = 'Google: Auth Extensions (JID Domain Discovery, OAuth2)' + dependencies = set(['feature_mechanisms']) + stanza = stanza + + def plugin_init(self): + self.xmpp.namespace_map['http://www.google.com/talk/protocol/auth'] = 'ga' + + register_stanza_plugin(self.xmpp['feature_mechanisms'].stanza.Auth, + stanza.GoogleAuth) + + self.xmpp.add_filter('out', self._auth) + + def plugin_end(self): + self.xmpp.del_filter('out', self._auth) + + def _auth(self, stanza): + if isinstance(stanza, self.xmpp['feature_mechanisms'].stanza.Auth): + stanza.stream = self.xmpp + stanza['google']['client_uses_full_bind_result'] = True + if stanza['mechanism'] == 'X-OAUTH2': + stanza['google']['service'] = 'oauth2' + print(stanza) + return stanza diff --git a/sleekxmpp/plugins/google/auth/stanza.py b/sleekxmpp/plugins/google/auth/stanza.py new file mode 100644 index 00000000..49c5cba7 --- /dev/null +++ b/sleekxmpp/plugins/google/auth/stanza.py @@ -0,0 +1,49 @@ +""" + SleekXMPP: The Sleek XMPP Library + Copyright (C) 2013 Nathanael C. Fritz, Lance J.T. Stout + This file is part of SleekXMPP. + + See the file LICENSE for copying permission. +""" + +from sleekxmpp.xmlstream import ElementBase, ET + + +class GoogleAuth(ElementBase): + name = 'auth' + namespace = 'http://www.google.com/talk/protocol/auth' + plugin_attrib = 'google' + interfaces = set(['client_uses_full_bind_result', 'service']) + + discovery_attr= '{%s}client-uses-full-bind-result' % namespace + service_attr= '{%s}service' % namespace + + def setup(self, xml): + """Don't create XML for the plugin.""" + self.xml = ET.Element('') + print('setting up google extension') + + def get_client_uses_full_bind_result(self): + return self.parent()._get_attr(self.disovery_attr) == 'true' + + def set_client_uses_full_bind_result(self, value): + print('>>>', value) + if value in (True, 'true'): + self.parent()._set_attr(self.discovery_attr, 'true') + else: + self.parent()._del_attr(self.discovery_attr) + + def del_client_uses_full_bind_result(self): + self.parent()._del_attr(self.discovery_attr) + + def get_service(self): + return self.parent()._get_attr(self.service_attr, '') + + def set_service(self, value): + if value: + self.parent()._set_attr(self.service_attr, value) + else: + self.parent()._del_attr(self.service_attr) + + def del_service(self): + self.parent()._del_attr(self.service_attr) diff --git a/sleekxmpp/plugins/google/gmail/__init__.py b/sleekxmpp/plugins/google/gmail/__init__.py new file mode 100644 index 00000000..a92e363b --- /dev/null +++ b/sleekxmpp/plugins/google/gmail/__init__.py @@ -0,0 +1,10 @@ +""" + SleekXMPP: The Sleek XMPP Library + Copyright (C) 2013 Nathanael C. Fritz, Lance J.T. Stout + This file is part of SleekXMPP. + + See the file LICENSE for copying permission. +""" + +from sleekxmpp.plugins.google.gmail import stanza +from sleekxmpp.plugins.google.gmail.notifications import Gmail diff --git a/sleekxmpp/plugins/google/gmail/notifications.py b/sleekxmpp/plugins/google/gmail/notifications.py new file mode 100644 index 00000000..6a0ceed4 --- /dev/null +++ b/sleekxmpp/plugins/google/gmail/notifications.py @@ -0,0 +1,77 @@ +""" + SleekXMPP: The Sleek XMPP Library + Copyright (C) 2013 Nathanael C. Fritz, Lance J.T. Stout + This file is part of SleekXMPP. + + See the file LICENSE for copying permission. +""" + +import logging + +from sleekxmpp.stanza import Iq +from sleekxmpp.xmlstream.handler import Callback +from sleekxmpp.xmlstream.matcher import MatchXPath +from sleekxmpp.xmlstream import register_stanza_plugin +from sleekxmpp.plugins import BasePlugin +from sleekxmpp.plugins.google.gmail import stanza + + +log = logging.getLogger(__name__) + + +class Gmail(BasePlugin): + + """ + Google: Gmail Notifications + + Also see . + """ + + name = 'gmail' + description = 'Google: Gmail Notifications' + dependencies = set() + stanza = stanza + + def plugin_init(self): + register_stanza_plugin(Iq, stanza.GmailQuery) + register_stanza_plugin(Iq, stanza.MailBox) + register_stanza_plugin(Iq, stanza.NewMail) + + self.xmpp.register_handler( + Callback('Gmail New Mail', + MatchXPath('{%s}iq/{%s}%s' % ( + self.xmpp.default_ns, + stanza.NewMail.namespace, + stanza.NewMail.name)), + self._handle_new_mail)) + + self._last_result_time = None + + def plugin_end(self): + self.xmpp.remove_handler('Gmail New Mail') + + def _handle_new_mail(self, iq): + log.info("Gmail: New email!") + iq.reply().send() + self.xmpp.event('gmail_notification') + + def check(self, block=True, timeout=None, callback=None): + last_time = self._last_result_time + self._last_result_time = str(int(time.time() * 1000)) + return self.search(newer=last_time, + block=block, + timeout=timeout, + callback=callback) + + def search(self, query=None, newer=None, block=True, + timeout=None, callback=None): + if not query: + log.info('Gmail: Checking for new email') + else: + log.info('Gmail: Searching for emails matching: "%s"', query) + iq = self.xmpp.Iq() + iq['type'] = 'get' + iq['to'] = self.xmpp.boundjid.bare + iq['gmail']['search'] = query + iq['gmail']['newer_than_time'] = newer + return iq.send(block=block, timeout=timeout, callback=callback) diff --git a/sleekxmpp/plugins/google/gmail/stanza.py b/sleekxmpp/plugins/google/gmail/stanza.py new file mode 100644 index 00000000..e7e308e1 --- /dev/null +++ b/sleekxmpp/plugins/google/gmail/stanza.py @@ -0,0 +1,101 @@ +""" + SleekXMPP: The Sleek XMPP Library + Copyright (C) 2013 Nathanael C. Fritz, Lance J.T. Stout + This file is part of SleekXMPP. + + See the file LICENSE for copying permission. +""" + +from sleekxmpp.xmlstream import ElementBase, register_stanza_plugin + + +class GmailQuery(ElementBase): + namespace = 'google:mail:notify' + name = 'query' + plugin_attrib = 'gmail' + interfaces = set(['newer_than_time', 'newer_than_tid', 'search']) + + def get_search(self): + return self._get_attr('q', '') + + def set_search(self, search): + self._set_attr('q', search) + + def del_search(self): + self._del_attr('q') + + def get_newer_than_time(self): + return self._get_attr('newer-than-time', '') + + def set_newer_than_time(self, value): + self._set_attr('newer-than-time', value) + + def del_newer_than_time(self): + self._del_attr('newer-than-time') + + def get_newer_than_tid(self): + return self._get_attr('newer-than-tid', '') + + def set_newer_than_tid(self, value): + self._set_attr('newer-than-tid', value) + + def del_newer_than_tid(self): + self._del_attr('newer-than-tid') + + +class MailBox(ElementBase): + namespace = 'google:mail:notify' + name = 'mailbox' + plugin_attrib = 'gmail_messages' + interfaces = set(['result_time', 'url', 'matched', 'estimate']) + + def get_matched(self): + return self._get_attr('total-matched', '') + + def get_estimate(self): + return self._get_attr('total-estimate', '') == '1' + + def get_result_time(self): + return self._get_attr('result-time', '') + + +class MailThread(ElementBase): + namespace = 'google:mail:notify' + name = 'mail-thread-info' + plugin_attrib = 'thread' + plugin_multi_attrib = 'threads' + interfaces = set(['tid', 'participation', 'messages', 'date', + 'senders', 'url', 'labels', 'subject', 'snippet']) + sub_interfaces = set(['labels', 'subject', 'snippet']) + + def get_senders(self): + result = [] + senders = self.xml.findall('{%s}senders/{%s}sender' % ( + self.namespace, self.namespace)) + + for sender in senders: + result.append(MailSender(xml=sender)) + + return result + + +class MailSender(ElementBase): + namespace = 'google:mail:notify' + name = 'sender' + plugin_attrib = name + interfaces = set(['address', 'name', 'originator', 'unread']) + + def get_originator(self): + return self.xml.attrib.get('originator', '0') == '1' + + def get_unread(self): + return self.xml.attrib.get('unread', '0') == '1' + + +class NewMail(ElementBase): + namespace = 'google:mail:notify' + name = 'new-mail' + plugin_attrib = 'gmail_notification' + + +register_stanza_plugin(MailBox, MailThread, iterable=True) diff --git a/sleekxmpp/plugins/google/nosave/__init__.py b/sleekxmpp/plugins/google/nosave/__init__.py new file mode 100644 index 00000000..57847af5 --- /dev/null +++ b/sleekxmpp/plugins/google/nosave/__init__.py @@ -0,0 +1,10 @@ +""" + SleekXMPP: The Sleek XMPP Library + Copyright (C) 2013 Nathanael C. Fritz, Lance J.T. Stout + This file is part of SleekXMPP. + + See the file LICENSE for copying permission. +""" + +from sleekxmpp.plugins.google.nosave import stanza +from sleekxmpp.plugins.google.nosave.nosave import GoogleNoSave diff --git a/sleekxmpp/plugins/google/nosave/nosave.py b/sleekxmpp/plugins/google/nosave/nosave.py new file mode 100644 index 00000000..d6bef615 --- /dev/null +++ b/sleekxmpp/plugins/google/nosave/nosave.py @@ -0,0 +1,83 @@ +""" + SleekXMPP: The Sleek XMPP Library + Copyright (C) 2013 Nathanael C. Fritz, Lance J.T. Stout + This file is part of SleekXMPP. + + See the file LICENSE for copying permission. +""" + +import logging + +from sleekxmpp.stanza import Iq, Message +from sleekxmpp.xmlstream.handler import Callback +from sleekxmpp.xmlstream.matcher import StanzaPath +from sleekxmpp.xmlstream import register_stanza_plugin +from sleekxmpp.plugins import BasePlugin +from sleekxmpp.plugins.google.nosave import stanza + + +log = logging.getLogger(__name__) + + +class GoogleNoSave(BasePlugin): + + """ + Google: Off the Record Chats + + NOTE: This is NOT an encryption method. + + Also see . + """ + + name = 'google_nosave' + description = 'Google: Off the Record Chats' + dependencies = set(['google_settings']) + stanza = stanza + + def plugin_init(self): + register_stanza_plugin(Message, stanza.NoSave) + register_stanza_plugin(Iq, stanza.NoSaveQuery) + + self.xmpp.register_handler( + Callback('Google Nosave', + StanzaPath('iq@type=set/google_nosave'), + self._handle_nosave_change)) + + def plugin_end(self): + self.xmpp.remove_handler('Google Nosave') + + def enable(self, jid=None, block=True, timeout=None, callback=None): + if jid is None: + self.xmpp['google_settings'].update({'archiving_enabled': False}, + block=block, timeout=timeout, callback=callback) + else: + iq = self.xmpp.Iq() + iq['type'] = 'set' + iq['google_nosave']['item']['jid'] = jid + iq['google_nosave']['item']['value'] = True + return iq.send(block=block, timeout=timeout, callback=callback) + + def disable(self, jid=None, block=True, timeout=None, callback=None): + if jid is None: + self.xmpp['google_settings'].update({'archiving_enabled': True}, + block=block, timeout=timeout, callback=callback) + else: + iq = self.xmpp.Iq() + iq['type'] = 'set' + iq['google_nosave']['item']['jid'] = jid + iq['google_nosave']['item']['value'] = False + return iq.send(block=block, timeout=timeout, callback=callback) + + def get(self, block=True, timeout=None, callback=None): + iq = self.xmpp.Iq() + iq['type'] = 'get' + iq.enable('google_nosave') + return iq.send(block=block, timeout=timeout, callback=callback) + + def _handle_nosave_change(self, iq): + reply = self.xmpp.Iq() + reply['type'] = 'result' + reply['id'] = iq['id'] + reply['to'] = iq['from'] + reply.send() + self.xmpp.event('google_nosave_change', iq) diff --git a/sleekxmpp/plugins/google/nosave/stanza.py b/sleekxmpp/plugins/google/nosave/stanza.py new file mode 100644 index 00000000..d8701322 --- /dev/null +++ b/sleekxmpp/plugins/google/nosave/stanza.py @@ -0,0 +1,59 @@ +""" + SleekXMPP: The Sleek XMPP Library + Copyright (C) 2013 Nathanael C. Fritz, Lance J.T. Stout + This file is part of SleekXMPP. + + See the file LICENSE for copying permission. +""" + +from sleekxmpp.jid import JID +from sleekxmpp.xmlstream import ElementBase, register_stanza_plugin + + +class NoSave(ElementBase): + name = 'x' + namespace = 'google:nosave' + plugin_attrib = 'google_nosave' + interfaces = set(['value']) + + def get_value(self): + return self._get_attr('value', '') == 'enabled' + + def set_value(self, value): + self._set_attr('value', 'enabled' if value else 'disabled') + + +class NoSaveQuery(ElementBase): + name = 'query' + namespace = 'google:nosave' + plugin_attrib = 'google_nosave' + interfaces = set() + + +class Item(ElementBase): + name = 'item' + namespace = 'google:nosave' + plugin_attrib = 'item' + plugin_multi_attrib = 'items' + interfaces = set(['jid', 'source', 'value']) + + def get_value(self): + return self._get_attr('value', '') == 'enabled' + + def set_value(self, value): + self._set_attr('value', 'enabled' if value else 'disabled') + + def get_jid(self): + return JID(self._get_attr('jid', '')) + + def set_jid(self, value): + self._set_attr('jid', str(value)) + + def get_source(self): + return JID(self._get_attr('source', '')) + + def set_source(self): + self._set_attr('source', str(value)) + + +register_stanza_plugin(NoSaveQuery, Item) diff --git a/sleekxmpp/plugins/google/settings/__init__.py b/sleekxmpp/plugins/google/settings/__init__.py new file mode 100644 index 00000000..c3a0471d --- /dev/null +++ b/sleekxmpp/plugins/google/settings/__init__.py @@ -0,0 +1,10 @@ +""" + SleekXMPP: The Sleek XMPP Library + Copyright (C) 2013 Nathanael C. Fritz, Lance J.T. Stout + This file is part of SleekXMPP. + + See the file LICENSE for copying permission. +""" + +from sleekxmpp.plugins.google.settings import stanza +from sleekxmpp.plugins.google.settings.settings import GoogleSettings diff --git a/sleekxmpp/plugins/google/settings/settings.py b/sleekxmpp/plugins/google/settings/settings.py new file mode 100644 index 00000000..7122ff56 --- /dev/null +++ b/sleekxmpp/plugins/google/settings/settings.py @@ -0,0 +1,65 @@ +""" + SleekXMPP: The Sleek XMPP Library + Copyright (C) 2013 Nathanael C. Fritz, Lance J.T. Stout + This file is part of SleekXMPP. + + See the file LICENSE for copying permission. +""" + +import logging + +from sleekxmpp.stanza import Iq +from sleekxmpp.xmlstream.handler import Callback +from sleekxmpp.xmlstream.matcher import StanzaPath +from sleekxmpp.xmlstream import register_stanza_plugin +from sleekxmpp.plugins import BasePlugin +from sleekxmpp.plugins.google.settings import stanza + + +class GoogleSettings(BasePlugin): + + """ + Google: Gmail Notifications + + Also see . + """ + + name = 'google_settings' + description = 'Google: User Settings' + dependencies = set() + stanza = stanza + + def plugin_init(self): + register_stanza_plugin(Iq, stanza.UserSettings) + + self.xmpp.register_handler( + Callback('Google Settings', + StanzaPath('iq@type=set/google_settings'), + self._handle_settings_change)) + + def plugin_end(self): + self.xmpp.remove_handler('Google Settings') + + def get(self, block=True, timeout=None, callback=None): + iq = self.xmpp.Iq() + iq['type'] = 'get' + iq.enable('google_settings') + return iq.send(block=block, timeout=timeout, callback=callback) + + def update(self, settings, block=True, timeout=None, callback=None): + iq = self.xmpp.Iq() + iq['type'] = 'set' + iq.enable('google_settings') + + for setting, value in settings.items(): + iq['google_settings'][setting] = value + + return iq.send(block=block, timeout=timeout, callback=callback) + + def _handle_settings_change(self, iq): + reply = self.xmpp.Iq() + reply['type'] = 'result' + reply['id'] = iq['id'] + reply['to'] = iq['from'] + reply.send() + self.xmpp.event('google_settings_change', iq) diff --git a/sleekxmpp/plugins/google/settings/stanza.py b/sleekxmpp/plugins/google/settings/stanza.py new file mode 100644 index 00000000..d8161770 --- /dev/null +++ b/sleekxmpp/plugins/google/settings/stanza.py @@ -0,0 +1,110 @@ +""" + SleekXMPP: The Sleek XMPP Library + Copyright (C) 2013 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 UserSettings(ElementBase): + name = 'usersetting' + namespace = 'google:setting' + plugin_attrib = 'google_settings' + interfaces = set(['auto_accept_suggestions', + 'mail_notifications', + 'archiving_enabled', + 'gmail', + 'email_verified', + 'domain_privacy_notice', + 'display_name']) + + def _get_setting(self, setting): + xml = self.xml.find('{%s}%s' % (self.namespace, setting)) + if xml is not None: + return xml.attrib.get('value', '') == 'true' + return False + + def _set_setting(self, setting, value): + self._del_setting(setting) + if value in (True, False): + xml = ET.Element('{%s}%s' % (self.namespace, setting)) + xml.attrib['value'] = 'true' if value else 'false' + self.xml.append(xml) + + def _del_setting(self, setting): + xml = self.xml.find('{%s}%s' % (self.namespace, setting)) + if xml is not None: + self.xml.remove(xml) + + def get_display_name(self): + xml = self.xml.find('{%s}%s' % (self.namespace, 'displayname')) + if xml is not None: + return xml.attrib.get('value', '') + return '' + + def set_display_name(self, value): + self._del_setting(setting) + if value: + xml = ET.Element('{%s}%s' % (self.namespace, 'displayname')) + xml.attrib['value'] = value + self.xml.append(xml) + + def del_display_name(self): + self._del_setting('displayname') + + def get_auto_accept_suggestions(self): + return self._get_setting('autoacceptsuggestions') + + def get_mail_notifications(self): + return self._get_setting('mailnotifications') + + def get_archiving_enabled(self): + return self._get_setting('archivingenabled') + + def get_gmail(self): + return self._get_setting('gmail') + + def get_email_verified(self): + return self._get_setting('emailverified') + + def get_domain_privacy_notice(self): + return self._get_setting('domainprivacynotice') + + def set_auto_accept_suggestions(self, value): + self._set_setting('autoacceptsuggestions', value) + + def set_mail_notifications(self, value): + self._set_setting('mailnotifications', value) + + def set_archiving_enabled(self, value): + self._set_setting('archivingenabled', value) + + def set_gmail(self, value): + self._set_setting('gmail', value) + + def set_email_verified(self, value): + self._set_setting('emailverified', value) + + def set_domain_privacy_notice(self, value): + self._set_setting('domainprivacynotice', value) + + def del_auto_accept_suggestions(self): + self._del_setting('autoacceptsuggestions') + + def del_mail_notifications(self): + self._del_setting('mailnotifications') + + def del_archiving_enabled(self): + self._del_setting('archivingenabled') + + def del_gmail(self): + self._del_setting('gmail') + + def del_email_verified(self): + self._del_setting('emailverified') + + def del_domain_privacy_notice(self): + self._del_setting('domainprivacynotice') diff --git a/sleekxmpp/plugins/google_domain_discovery/__init__.py b/sleekxmpp/plugins/google_domain_discovery/__init__.py deleted file mode 100644 index 828d1859..00000000 --- a/sleekxmpp/plugins/google_domain_discovery/__init__.py +++ /dev/null @@ -1,15 +0,0 @@ -""" - SleekXMPP: The Sleek XMPP Library - Copyright (C) 2013 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.google_domain_discovery import stanza -from sleekxmpp.plugins.google_domain_discovery.auth import GoogleDomainDiscovery - - -register_plugin(GoogleDomainDiscovery) diff --git a/sleekxmpp/plugins/google_domain_discovery/auth.py b/sleekxmpp/plugins/google_domain_discovery/auth.py deleted file mode 100644 index 4de35f9f..00000000 --- a/sleekxmpp/plugins/google_domain_discovery/auth.py +++ /dev/null @@ -1,49 +0,0 @@ -""" - SleekXMPP: The Sleek XMPP Library - Copyright (C) 2013 Nathanael C. Fritz, Lance J.T. Stout - This file is part of SleekXMPP. - - See the file LICENSE for copying permission. -""" - -import logging - -from sleekxmpp.stanza import Iq, Message -from sleekxmpp.xmlstream.handler import Callback -from sleekxmpp.xmlstream.matcher import StanzaPath -from sleekxmpp.xmlstream import register_stanza_plugin -from sleekxmpp.plugins import BasePlugin -from sleekxmpp.plugins.google_domain_discovery import stanza - - -log = logging.getLogger(__name__) - - -class GoogleDomainDiscovery(BasePlugin): - - """ - Google: JID Domain Discovery - - Also see . - """ - - name = 'google_nosave' - description = 'Google: Off the Record Chats' - dependencies = set(['google_settings']) - stanza = stanza - - def plugin_init(self): - register_stanza_plugin(Message, stanza.NoSave) - register_stanza_plugin(Iq, stanza.NoSaveQuery) - - self.xmpp.register_handler( - Callback('Google Nosave', - StanzaPath('iq@type=set/google_nosave'), - self._handle_nosave_change)) - - def plugin_end(self): - self.xmpp.remove_handler('Google Nosave') - - def enable(self, jid=None, block=True, timeout=None, callback=None): - if jid is None: - self.xmpp['google_settings'].update({'archiving_enabled': False}, - block=block, timeout=timeout, callback=callback) - else: - iq = self.xmpp.Iq() - iq['type'] = 'set' - iq['google_nosave']['item']['jid'] = jid - iq['google_nosave']['item']['value'] = True - return iq.send(block=block, timeout=timeout, callback=callback) - - def disable(self, jid=None, block=True, timeout=None, callback=None): - if jid is None: - self.xmpp['google_settings'].update({'archiving_enabled': True}, - block=block, timeout=timeout, callback=callback) - else: - iq = self.xmpp.Iq() - iq['type'] = 'set' - iq['google_nosave']['item']['jid'] = jid - iq['google_nosave']['item']['value'] = False - return iq.send(block=block, timeout=timeout, callback=callback) - - def get(self, block=True, timeout=None, callback=None): - iq = self.xmpp.Iq() - iq['type'] = 'get' - iq.enable('google_nosave') - return iq.send(block=block, timeout=timeout, callback=callback) - - def _handle_nosave_change(self, iq): - reply = self.xmpp.Iq() - reply['type'] = 'result' - reply['id'] = iq['id'] - reply['to'] = iq['from'] - reply.send() - self.xmpp.event('google_nosave_change', iq) diff --git a/sleekxmpp/plugins/google_nosave/stanza.py b/sleekxmpp/plugins/google_nosave/stanza.py deleted file mode 100644 index d8701322..00000000 --- a/sleekxmpp/plugins/google_nosave/stanza.py +++ /dev/null @@ -1,59 +0,0 @@ -""" - SleekXMPP: The Sleek XMPP Library - Copyright (C) 2013 Nathanael C. Fritz, Lance J.T. Stout - This file is part of SleekXMPP. - - See the file LICENSE for copying permission. -""" - -from sleekxmpp.jid import JID -from sleekxmpp.xmlstream import ElementBase, register_stanza_plugin - - -class NoSave(ElementBase): - name = 'x' - namespace = 'google:nosave' - plugin_attrib = 'google_nosave' - interfaces = set(['value']) - - def get_value(self): - return self._get_attr('value', '') == 'enabled' - - def set_value(self, value): - self._set_attr('value', 'enabled' if value else 'disabled') - - -class NoSaveQuery(ElementBase): - name = 'query' - namespace = 'google:nosave' - plugin_attrib = 'google_nosave' - interfaces = set() - - -class Item(ElementBase): - name = 'item' - namespace = 'google:nosave' - plugin_attrib = 'item' - plugin_multi_attrib = 'items' - interfaces = set(['jid', 'source', 'value']) - - def get_value(self): - return self._get_attr('value', '') == 'enabled' - - def set_value(self, value): - self._set_attr('value', 'enabled' if value else 'disabled') - - def get_jid(self): - return JID(self._get_attr('jid', '')) - - def set_jid(self, value): - self._set_attr('jid', str(value)) - - def get_source(self): - return JID(self._get_attr('source', '')) - - def set_source(self): - self._set_attr('source', str(value)) - - -register_stanza_plugin(NoSaveQuery, Item) diff --git a/sleekxmpp/plugins/google_settings/__init__.py b/sleekxmpp/plugins/google_settings/__init__.py deleted file mode 100644 index ef4b2342..00000000 --- a/sleekxmpp/plugins/google_settings/__init__.py +++ /dev/null @@ -1,15 +0,0 @@ -""" - SleekXMPP: The Sleek XMPP Library - Copyright (C) 2013 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.google_settings import stanza -from sleekxmpp.plugins.google_settings.settings import GoogleSettings - - -register_plugin(GoogleSettings) diff --git a/sleekxmpp/plugins/google_settings/settings.py b/sleekxmpp/plugins/google_settings/settings.py deleted file mode 100644 index 6bd209c7..00000000 --- a/sleekxmpp/plugins/google_settings/settings.py +++ /dev/null @@ -1,68 +0,0 @@ -""" - SleekXMPP: The Sleek XMPP Library - Copyright (C) 2013 Nathanael C. Fritz, Lance J.T. Stout - This file is part of SleekXMPP. - - See the file LICENSE for copying permission. -""" - -import logging - -from sleekxmpp.stanza import Iq -from sleekxmpp.xmlstream.handler import Callback -from sleekxmpp.xmlstream.matcher import StanzaPath -from sleekxmpp.xmlstream import register_stanza_plugin -from sleekxmpp.plugins import BasePlugin -from sleekxmpp.plugins.google_settings import stanza - - -log = logging.getLogger(__name__) - - -class GoogleSettings(BasePlugin): - - """ - Google: Gmail Notifications - - Also see . - """ - - name = 'google_settings' - description = 'Google: User Settings' - dependencies = set() - stanza = stanza - - def plugin_init(self): - register_stanza_plugin(Iq, stanza.UserSettings) - - self.xmpp.register_handler( - Callback('Google Settings', - StanzaPath('iq@type=set/google_settings'), - self._handle_settings_change)) - - def plugin_end(self): - self.xmpp.remove_handler('Google Settings') - - def get(self, block=True, timeout=None, callback=None): - iq = self.xmpp.Iq() - iq['type'] = 'get' - iq.enable('google_settings') - return iq.send(block=block, timeout=timeout, callback=callback) - - def update(self, settings, block=True, timeout=None, callback=None): - iq = self.xmpp.Iq() - iq['type'] = 'set' - iq.enable('google_settings') - - for setting, value in settings.items(): - iq['google_settings'][setting] = value - - return iq.send(block=block, timeout=timeout, callback=callback) - - def _handle_settings_change(self, iq): - reply = self.xmpp.Iq() - reply['type'] = 'result' - reply['id'] = iq['id'] - reply['to'] = iq['from'] - reply.send() - self.xmpp.event('google_settings_change', iq) diff --git a/sleekxmpp/plugins/google_settings/stanza.py b/sleekxmpp/plugins/google_settings/stanza.py deleted file mode 100644 index d8161770..00000000 --- a/sleekxmpp/plugins/google_settings/stanza.py +++ /dev/null @@ -1,110 +0,0 @@ -""" - SleekXMPP: The Sleek XMPP Library - Copyright (C) 2013 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 UserSettings(ElementBase): - name = 'usersetting' - namespace = 'google:setting' - plugin_attrib = 'google_settings' - interfaces = set(['auto_accept_suggestions', - 'mail_notifications', - 'archiving_enabled', - 'gmail', - 'email_verified', - 'domain_privacy_notice', - 'display_name']) - - def _get_setting(self, setting): - xml = self.xml.find('{%s}%s' % (self.namespace, setting)) - if xml is not None: - return xml.attrib.get('value', '') == 'true' - return False - - def _set_setting(self, setting, value): - self._del_setting(setting) - if value in (True, False): - xml = ET.Element('{%s}%s' % (self.namespace, setting)) - xml.attrib['value'] = 'true' if value else 'false' - self.xml.append(xml) - - def _del_setting(self, setting): - xml = self.xml.find('{%s}%s' % (self.namespace, setting)) - if xml is not None: - self.xml.remove(xml) - - def get_display_name(self): - xml = self.xml.find('{%s}%s' % (self.namespace, 'displayname')) - if xml is not None: - return xml.attrib.get('value', '') - return '' - - def set_display_name(self, value): - self._del_setting(setting) - if value: - xml = ET.Element('{%s}%s' % (self.namespace, 'displayname')) - xml.attrib['value'] = value - self.xml.append(xml) - - def del_display_name(self): - self._del_setting('displayname') - - def get_auto_accept_suggestions(self): - return self._get_setting('autoacceptsuggestions') - - def get_mail_notifications(self): - return self._get_setting('mailnotifications') - - def get_archiving_enabled(self): - return self._get_setting('archivingenabled') - - def get_gmail(self): - return self._get_setting('gmail') - - def get_email_verified(self): - return self._get_setting('emailverified') - - def get_domain_privacy_notice(self): - return self._get_setting('domainprivacynotice') - - def set_auto_accept_suggestions(self, value): - self._set_setting('autoacceptsuggestions', value) - - def set_mail_notifications(self, value): - self._set_setting('mailnotifications', value) - - def set_archiving_enabled(self, value): - self._set_setting('archivingenabled', value) - - def set_gmail(self, value): - self._set_setting('gmail', value) - - def set_email_verified(self, value): - self._set_setting('emailverified', value) - - def set_domain_privacy_notice(self, value): - self._set_setting('domainprivacynotice', value) - - def del_auto_accept_suggestions(self): - self._del_setting('autoacceptsuggestions') - - def del_mail_notifications(self): - self._del_setting('mailnotifications') - - def del_archiving_enabled(self): - self._del_setting('archivingenabled') - - def del_gmail(self): - self._del_setting('gmail') - - def del_email_verified(self): - self._del_setting('emailverified') - - def del_domain_privacy_notice(self): - self._del_setting('domainprivacynotice') -- cgit v1.2.3