summaryrefslogtreecommitdiff
path: root/sleekxmpp/xmlstream
diff options
context:
space:
mode:
authorLance Stout <lancestout@gmail.com>2011-01-26 10:04:36 -0500
committerLance Stout <lancestout@gmail.com>2011-01-26 10:04:36 -0500
commit4e757c2b56e7c4ded0a3de9e49c550db36da72d2 (patch)
treec3791b06d96abc9130d3222069c8f1cfbe171866 /sleekxmpp/xmlstream
parentc3be6ea0b2141fe86b9aa0c2701e43b72f86ae30 (diff)
downloadslixmpp-4e757c2b56e7c4ded0a3de9e49c550db36da72d2.tar.gz
slixmpp-4e757c2b56e7c4ded0a3de9e49c550db36da72d2.tar.bz2
slixmpp-4e757c2b56e7c4ded0a3de9e49c550db36da72d2.tar.xz
slixmpp-4e757c2b56e7c4ded0a3de9e49c550db36da72d2.zip
Upgraded how subitem works.
May now use register_stanza_plugin(Foo, Bar, iterable=True) to add to the set of stanza classes used for iterable substanzas. It is no longer necessary to manually specify the contents of subitem if the new method is used.
Diffstat (limited to 'sleekxmpp/xmlstream')
-rw-r--r--sleekxmpp/xmlstream/stanzabase.py26
1 files changed, 19 insertions, 7 deletions
diff --git a/sleekxmpp/xmlstream/stanzabase.py b/sleekxmpp/xmlstream/stanzabase.py
index 2c008668..764aaca7 100644
--- a/sleekxmpp/xmlstream/stanzabase.py
+++ b/sleekxmpp/xmlstream/stanzabase.py
@@ -23,17 +23,23 @@ log = logging.getLogger(__name__)
XML_TYPE = type(ET.Element('xml'))
-def register_stanza_plugin(stanza, plugin):
+def register_stanza_plugin(stanza, plugin, iterable=False):
"""
Associate a stanza object as a plugin for another stanza.
Arguments:
- stanza -- The class of the parent stanza.
- plugin -- The class of the plugin stanza.
+ stanza -- The class of the parent stanza.
+ plugin -- The class of the plugin stanza.
+ iterable -- Indicates if the plugin stanza
+ should be included in the parent
+ stanza's iterable 'substanzas'
+ interface results.
"""
tag = "{%s}%s" % (plugin.namespace, plugin.name)
stanza.plugin_attrib_map[plugin.plugin_attrib] = plugin
stanza.plugin_tag_map[tag] = plugin
+ if iterable:
+ stanza.plugin_iterables.add(plugin)
# To maintain backwards compatibility for now, preserve the camel case name.
@@ -120,12 +126,15 @@ class ElementBase(object):
sub_interfaces -- A subset of the set of interfaces which map
to subelements instead of attributes.
subitem -- A set of stanza classes which are allowed to
- be added as substanzas.
+ be added as substanzas. Deprecated version
+ of plugin_iterables.
types -- A set of generic type attribute values.
plugin_attrib -- The interface name that the stanza uses to be
accessed as a plugin from another stanza.
plugin_attrib_map -- A mapping of plugin attribute names with the
associated plugin stanza classes.
+ plugin_iterables -- A set of stanza classes which are allowed to
+ be added as substanzas.
plugin_tag_map -- A mapping of plugin stanza tag names with
the associated plugin stanza classes.
is_extension -- When True, allows the stanza to provide one
@@ -187,6 +196,7 @@ class ElementBase(object):
types = set(('get', 'set', 'error', None, 'unavailable', 'normal', 'chat'))
sub_interfaces = tuple()
plugin_attrib_map = {}
+ plugin_iterables = set()
plugin_tag_map = {}
subitem = None
is_extension = False
@@ -235,9 +245,11 @@ class ElementBase(object):
self.plugins[plugin.plugin_attrib] = plugin(child, self)
if self.subitem is not None:
for sub in self.subitem:
- if child.tag == "{%s}%s" % (sub.namespace, sub.name):
- self.iterables.append(sub(child, self))
- break
+ self.plugin_iterables.add(sub)
+ for sub in self.plugin_iterables:
+ if child.tag == "{%s}%s" % (sub.namespace, sub.name):
+ self.iterables.append(sub(child, self))
+ break
def setup(self, xml=None):
"""