slixmpp/sleekxmpp/xmlstream
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
..
handler Fix RESPONSE_TIMEOUT dependency loops. 2010-11-17 15:13:09 -05:00
matcher Make live stream tests work better. 2010-11-17 13:43:15 -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 scheduler no longer waits for the next event before exiting 2010-11-16 17:58:20 -08:00
stanzabase.py Make extending stanza objects nicer. 2011-01-19 19:49:13 -05: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 Raise the event 'socket_error' when a socket error occurs. 2011-01-16 13:07:39 -05:00