SleekXMPP/sleekxmpp
Lance Stout da332365d4 Make extending stanza objects nicer.
A stanza object may add is_extension = True to its class definition
to provide a single new interface to a parent stanza.

For example:

import sleekxmpp
from sleekxmpp import Iq
from sleekxmpp.xmlstream import ElementBase, register_stanza_plugin, ET

class Foo(ElementBase):
    """
    Test adding just an attribute to a parent stanza.

    Adding subelements works as expected.
    """
    is_extension = True
    interfaces = set(('foo',))
    plugin_attrib = '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, val):
        self.parent()._set_attr('foo', val)

    def get_foo(self):
        return self.parent()._get_attr('foo')

    def del_foo(self):
        self.parent()._del_attr('foo')

register_stanza_plugin(Iq, Foo)

i1 = Iq()
i2 = Iq(xml=ET.fromstring("<iq xmlns='jabber:client' foo='bar' />"))

>>> i1['foo'] = '3'
>>> i1
'3'
>>> i1
'<iq id="0" foo="3" />'
>>> i2
'<iq id="0" foo="bar" />'
>>> i2['foo']
'bar'
>>> del i2['foo']
>>> i2
'<iq id="0" />'
2011-01-19 19:49:13 -05:00
..
plugins Fix disco add_item. 2011-01-19 17:27:53 -05:00
stanza Fix namespace for Nick stanza. 2011-01-19 16:47:18 -05:00
test Fix several errors in SleekTest. 2010-12-07 23:04:37 -05:00
thirdparty Fix thirdparty imports for Python3 2011-01-19 17:49:39 -05:00
xmlstream Make extending stanza objects nicer. 2011-01-19 19:49:13 -05:00
__init__.py Moved ClientXMPP to clientxmpp.py. 2010-10-06 14:20:32 -04:00
basexmpp.py Add StreamError stanza and a stream_error event. 2011-01-16 13:22:52 -05:00
clientxmpp.py Do not traceback when DNS resolution time out. 2011-01-20 06:34:08 +08:00
componentxmpp.py Doesn't fail if host has NO SRV record 2010-11-09 01:53:41 +08:00
exceptions.py Made exceptions work. 2010-10-25 15:09:56 -04:00