summaryrefslogtreecommitdiff
path: root/sleekxmpp/clientxmpp.py
diff options
context:
space:
mode:
authorLance Stout <lancestout@gmail.com>2011-01-19 19:49:13 -0500
committerLance Stout <lancestout@gmail.com>2011-01-19 19:49:13 -0500
commitda332365d4e97720ac182e0f66b73919d764a555 (patch)
tree7cf55e9711a96b649cd12b9be62d52b43d5bb9de /sleekxmpp/clientxmpp.py
parentf7e7bf601e6bd65cdb85f44c67e05b9ba66b0aeb (diff)
downloadslixmpp-da332365d4e97720ac182e0f66b73919d764a555.tar.gz
slixmpp-da332365d4e97720ac182e0f66b73919d764a555.tar.bz2
slixmpp-da332365d4e97720ac182e0f66b73919d764a555.tar.xz
slixmpp-da332365d4e97720ac182e0f66b73919d764a555.zip
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" />'
Diffstat (limited to 'sleekxmpp/clientxmpp.py')
0 files changed, 0 insertions, 0 deletions