Refactor Google GTalk extensions into a single meta plugin.

This commit is contained in:
Lance Stout 2013-01-24 23:05:05 -08:00
parent 1741059cf6
commit a1b33da9ca
17 changed files with 145 additions and 104 deletions

View file

@ -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: <https://developers.google.com/talk/jep_extensions/extensions>
"""
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)

View file

@ -6,10 +6,5 @@
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)
from sleekxmpp.plugins.google.auth import stanza
from sleekxmpp.plugins.google.auth.auth import GoogleAuth

View file

@ -8,32 +8,31 @@
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
from sleekxmpp.plugins.google.auth import stanza
log = logging.getLogger(__name__)
class GoogleDomainDiscovery(BasePlugin):
class GoogleAuth(BasePlugin):
"""
Google: JID Domain Discovery
Google: Auth Extensions (JID Domain Discovery, OAuth2)
Also see <https://developers.google.com/talk/jep_extensions/jid_domain_change
Also see:
<https://developers.google.com/talk/jep_extensions/jid_domain_change>
<https://developers.google.com/talk/jep_extensions/oauth>
"""
name = 'google_domain_discovery'
description = 'Google: JID Domain Discovery'
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[stanza.GoogleAuth.namespace] = 'ga'
self.xmpp.namespace_map['http://www.google.com/talk/protocol/auth'] = 'ga'
register_stanza_plugin(self.xmpp['feature_mechanisms'].stanza.Auth,
stanza.GoogleAuth)
@ -45,5 +44,9 @@ class GoogleDomainDiscovery(BasePlugin):
def _auth(self, stanza):
if isinstance(stanza, self.xmpp['feature_mechanisms'].stanza.Auth):
stanza['use_full_bind_result'] = True
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

View file

@ -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)

View file

@ -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

View file

@ -13,7 +13,7 @@ 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
from sleekxmpp.plugins.google.gmail import stanza
log = logging.getLogger(__name__)

View file

@ -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

View file

@ -13,7 +13,7 @@ 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
from sleekxmpp.plugins.google.nosave import stanza
log = logging.getLogger(__name__)

View file

@ -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

View file

@ -13,10 +13,7 @@ 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__)
from sleekxmpp.plugins.google.settings import stanza
class GoogleSettings(BasePlugin):

View file

@ -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)

View file

@ -1,35 +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, ET
class GoogleAuth(ElementBase):
name = 'use_full_bind_result'
namespace = 'http://www.google.com/talk/protocol/auth'
plugin_attrib = name
interfaces = set([name])
is_extension = True
attribute = '{%s}client-users-full-bind-result' % namespace
def setup(self, xml):
"""Don't create XML for the plugin."""
self.xml = ET.Element('')
def get_use_full_bind_result(self):
return self.parent()._get_attr(self.attribute) == 'true'
def set_use_full_bind_result(self, value):
if value in (True, 'true'):
self.parent()._set_attr(self.attribute, 'true')
else:
self.parent()._del_attr(self.attribute)
def del_use_full_bind_result(self):
self.parent()._del_attr(self.attribute)

View file

@ -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_nosave import stanza
from sleekxmpp.plugins.google_nosave.nosave import GoogleNoSave
register_plugin(GoogleNoSave)

View file

@ -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)