summaryrefslogtreecommitdiff
path: root/sleekxmpp/plugins/google_nosave/nosave.py
diff options
context:
space:
mode:
authorLance Stout <lancestout@gmail.com>2013-01-21 01:39:08 -0800
committerLance Stout <lancestout@gmail.com>2013-01-21 01:39:08 -0800
commit4f9a95b011277ab64a137aceeb4df2e9fc0f1e25 (patch)
tree56c8c707b6bf14ae66e4e68ab2a74bf35b785990 /sleekxmpp/plugins/google_nosave/nosave.py
parent903e641457f30670af36a13b51ef0ab3e611bead (diff)
downloadslixmpp-4f9a95b011277ab64a137aceeb4df2e9fc0f1e25.tar.gz
slixmpp-4f9a95b011277ab64a137aceeb4df2e9fc0f1e25.tar.bz2
slixmpp-4f9a95b011277ab64a137aceeb4df2e9fc0f1e25.tar.xz
slixmpp-4f9a95b011277ab64a137aceeb4df2e9fc0f1e25.zip
Add plugin for Google's nosave feature.
Diffstat (limited to 'sleekxmpp/plugins/google_nosave/nosave.py')
-rw-r--r--sleekxmpp/plugins/google_nosave/nosave.py83
1 files changed, 83 insertions, 0 deletions
diff --git a/sleekxmpp/plugins/google_nosave/nosave.py b/sleekxmpp/plugins/google_nosave/nosave.py
new file mode 100644
index 00000000..1d3b36db
--- /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 <https://developers.google.com/talk/jep_extensions/otr>.
+ """
+
+ 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)