summaryrefslogtreecommitdiff
path: root/sleekxmpp/stanza/message.py
diff options
context:
space:
mode:
authorLance Stout <lancestout@gmail.com>2011-03-24 12:25:17 -0400
committerLance Stout <lancestout@gmail.com>2011-03-24 12:25:17 -0400
commit6d45971411f88f134abc28051c678986db8e9df8 (patch)
treea7e71c34ef8e539b262249f3bcc514975c314332 /sleekxmpp/stanza/message.py
parent84e2589f2205eb0b88fca92418c17950ab3a3f1b (diff)
downloadslixmpp-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/stanza/message.py')
0 files changed, 0 insertions, 0 deletions