This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Creating a SleekXMPP Plugin | |
This is a minimal implementation of XEP-0077 to serve | |
as a tutorial for creating SleekXMPP plugins. | |
""" | |
from . import base | |
class xep_0077(base.base_plugin): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def post_init(self): | |
base.base_plugin.post_init(self) | |
self.xmpp.plugin['xep-0030'].add_feature("jabber:iq:register") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from .. xmlstream.stanzabase import ElementBase, ET, JID | |
from .. stanza.iq import Iq | |
class Registration(ElementBase): | |
namespace = 'jabber:iq:register' | |
name = 'query' | |
plugin_attrib = 'register' | |
interfaces = set(('username', 'password', 'registered', 'remove')) | |
sub_interfaces = interfaces |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def plugin_init(self): | |
self.description = "In-Band Registration" | |
self.xep = "0077" | |
self.xmpp.registerHandler( | |
Callback('In-Band Registration', | |
MatchXPath('{%s}iq/{jabber:iq:register}query' % self.xmpp.default_ns), | |
self.__handleRegistration)) | |
self.xmpp.stanzaPlugin(Iq, Registration) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def plugin_init(self): | |
self.description = "In-Band Registration" | |
self.xep = "0077" | |
self.form_fields = ('username', 'password') | |
... remainder of plugin_init | |
... | |
def __handleRegistration(self, iq): | |
if iq['type'] == 'get': |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def __handleRegistration(self, iq): | |
if iq['type'] == 'get': | |
# Registration form requested | |
userData = self.backend[iq['from'].bare] | |
self.sendRegistrationForm(iq, userData) | |
elif iq['type'] == 'set': | |
# Remove an account | |
if iq['register']['remove']: | |
self.backend.unregister(iq['from'].bare) | |
self.xmpp.event('unregistered_user', iq) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def __handleRegistration(self, iq): | |
if iq['type'] == 'get': | |
# Registration form requested | |
userData = self.backend[iq['from'].bare] | |
self.sendRegistrationForm(iq, userData) | |
elif iq['type'] == 'set': | |
if iq['register']['remove']: | |
# Remove an account | |
self.backend.unregister(iq['from'].bare) | |
self.xmpp.event('unregistered_user', iq) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def __handleRegistration(self, iq): | |
if iq['type'] == 'get': | |
# Registration form requested | |
userData = self.backend[iq['from'].bare] | |
self.sendRegistrationForm(iq, userData) | |
elif iq['type'] == 'set': | |
if iq['register']['remove']: | |
# Remove an account | |
self.backend.unregister(iq['from'].bare) | |
self.xmpp.event('unregistered_user', iq) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sleekxmpp.componentxmpp | |
class Example(sleekxmpp.componentxmpp.ComponentXMPP): | |
def __init__(self, jid, password): | |
sleekxmpp.componentxmpp.ComponentXMPP.__init__(self, jid, password, 'localhost', 8888) | |
self.registerPlugin('xep_0030') | |
self.registerPlugin('xep_0077') | |
self.plugin['xep_0077'].setForm('username', 'password') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Creating a SleekXMPP Plugin | |
This is a minimal implementation of XEP-0077 to serve | |
as a tutorial for creating SleekXMPP plugins. | |
""" | |
from . import base | |
from .. xmlstream.handler.callback import Callback | |
from .. xmlstream.matcher.xpath import MatchXPath |
OlderNewer