mirror of
https://github.com/correl/SleekXMPP.git
synced 2024-11-24 03:00:15 +00:00
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.
This commit is contained in:
parent
c3be6ea0b2
commit
4e757c2b56
1 changed files with 19 additions and 7 deletions
|
@ -23,17 +23,23 @@ log = logging.getLogger(__name__)
|
||||||
XML_TYPE = type(ET.Element('xml'))
|
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.
|
Associate a stanza object as a plugin for another stanza.
|
||||||
|
|
||||||
Arguments:
|
Arguments:
|
||||||
stanza -- The class of the parent stanza.
|
stanza -- The class of the parent stanza.
|
||||||
plugin -- The class of the plugin 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)
|
tag = "{%s}%s" % (plugin.namespace, plugin.name)
|
||||||
stanza.plugin_attrib_map[plugin.plugin_attrib] = plugin
|
stanza.plugin_attrib_map[plugin.plugin_attrib] = plugin
|
||||||
stanza.plugin_tag_map[tag] = 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.
|
# 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
|
sub_interfaces -- A subset of the set of interfaces which map
|
||||||
to subelements instead of attributes.
|
to subelements instead of attributes.
|
||||||
subitem -- A set of stanza classes which are allowed to
|
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.
|
types -- A set of generic type attribute values.
|
||||||
plugin_attrib -- The interface name that the stanza uses to be
|
plugin_attrib -- The interface name that the stanza uses to be
|
||||||
accessed as a plugin from another stanza.
|
accessed as a plugin from another stanza.
|
||||||
plugin_attrib_map -- A mapping of plugin attribute names with the
|
plugin_attrib_map -- A mapping of plugin attribute names with the
|
||||||
associated plugin stanza classes.
|
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
|
plugin_tag_map -- A mapping of plugin stanza tag names with
|
||||||
the associated plugin stanza classes.
|
the associated plugin stanza classes.
|
||||||
is_extension -- When True, allows the stanza to provide one
|
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'))
|
types = set(('get', 'set', 'error', None, 'unavailable', 'normal', 'chat'))
|
||||||
sub_interfaces = tuple()
|
sub_interfaces = tuple()
|
||||||
plugin_attrib_map = {}
|
plugin_attrib_map = {}
|
||||||
|
plugin_iterables = set()
|
||||||
plugin_tag_map = {}
|
plugin_tag_map = {}
|
||||||
subitem = None
|
subitem = None
|
||||||
is_extension = False
|
is_extension = False
|
||||||
|
@ -235,6 +245,8 @@ class ElementBase(object):
|
||||||
self.plugins[plugin.plugin_attrib] = plugin(child, self)
|
self.plugins[plugin.plugin_attrib] = plugin(child, self)
|
||||||
if self.subitem is not None:
|
if self.subitem is not None:
|
||||||
for sub in self.subitem:
|
for sub in self.subitem:
|
||||||
|
self.plugin_iterables.add(sub)
|
||||||
|
for sub in self.plugin_iterables:
|
||||||
if child.tag == "{%s}%s" % (sub.namespace, sub.name):
|
if child.tag == "{%s}%s" % (sub.namespace, sub.name):
|
||||||
self.iterables.append(sub(child, self))
|
self.iterables.append(sub(child, self))
|
||||||
break
|
break
|
||||||
|
|
Loading…
Reference in a new issue