diff options
author | Lance Stout <lancestout@gmail.com> | 2011-03-24 12:25:17 -0400 |
---|---|---|
committer | Lance Stout <lancestout@gmail.com> | 2011-03-24 12:25:17 -0400 |
commit | 6d45971411f88f134abc28051c678986db8e9df8 (patch) | |
tree | a7e71c34ef8e539b262249f3bcc514975c314332 /sleekxmpp/plugins/xep_0249 | |
parent | 84e2589f2205eb0b88fca92418c17950ab3a3f1b (diff) | |
download | slixmpp-6d45971411f88f134abc28051c678986db8e9df8.tar.gz slixmpp-6d45971411f88f134abc28051c678986db8e9df8.tar.bz2 slixmpp-6d45971411f88f134abc28051c678986db8e9df8.tar.xz slixmpp-6d45971411f88f134abc28051c678986db8e9df8.zip |
Allow a stanza plugin to override a parent's interfaces.
Each interface, say foo, may be overridden in three ways:
set_foo
get_foo
del_foo
To declare an override in a plugin, add the class field
overrides as so:
overrides = ['set_foo', 'del_foo']
Each override must have a matching set_foo(), etc method
for implementing the new behaviour.
To enable the overrides for a particular parent stanza,
pass the option overrides=True to register_stanza_plugin.
register_stanza_plugin(Stanza, Plugin, overrides=True)
Example code:
class Test(ElementBase):
name = 'test'
namespace = 'testing'
interfaces = set(('foo', 'bar'))
sub_interfaces = set(('bar',))
class TestOverride(ElementBase):
name = 'test-override'
namespace = 'testing'
plugin_attrib = 'override'
interfaces = set(('foo',))
overrides = ['set_foo']
def setup(self, xml):
# Don't include an XML element in the parent stanza
# since we're adding just an attribute.
# If adding a regular subelement, no need to do this.
self.xml = ET.Element('')
def set_foo(self, value):
print("overrides!")
self.parent()._set_attr('foo', 'override-%s' % value)
register_stanza_plugin(Test, TestOverride, overrides=True)
Example usage:
>>> t = TestStanza()
>>> t['foo'] = 'bar'
>>> t['foo']
'override-bar'
Diffstat (limited to 'sleekxmpp/plugins/xep_0249')
0 files changed, 0 insertions, 0 deletions