SleekXMPP/sleekxmpp/xmlstream
Lance Stout 6d45971411 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'
2011-03-24 12:25:17 -04:00
..
handler Remap old method names in a better way. 2011-02-14 13:49:43 -05:00
matcher Remap old method names in a better way. 2011-02-14 13:49:43 -05:00
tostring Add support for using xml:lang values. 2010-12-07 23:07:40 -05:00
__init__.py Underscore names by default. 2010-10-17 22:04:42 -04:00
filesocket.py Fixed line spacing in filesocket.py to please pep8. 2010-09-01 14:25:30 -04:00
jid.py Fix bug in JID class. Attribute .jid now works properly. 2011-01-13 10:21:20 -05:00
scheduler.py Remap old method names in a better way. 2011-02-14 13:49:43 -05:00
stanzabase.py Allow a stanza plugin to override a parent's interfaces. 2011-03-24 12:25:17 -04:00
test.py moved seesmic branch to trunk 2009-06-03 22:56:51 +00:00
test.xml moved seesmic branch to trunk 2009-06-03 22:56:51 +00:00
testclient.py moved seesmic branch to trunk 2009-06-03 22:56:51 +00:00
xmlstream.py Fix self.disconnect(reconnect=True) not working. 2011-03-18 15:47:21 -04:00