stanza: rework the .append() and __eq__ methods
This was very much broken on plugin iterables and other reasons.
This commit is contained in:
parent
99c6fc923a
commit
eee185ff90
1 changed files with 17 additions and 10 deletions
|
@ -487,7 +487,7 @@ class ElementBase(object):
|
||||||
else:
|
else:
|
||||||
return None if check else self.init_plugin(name, lang)
|
return None if check else self.init_plugin(name, lang)
|
||||||
|
|
||||||
def init_plugin(self, attrib, lang=None, existing_xml=None, reuse=True):
|
def init_plugin(self, attrib, lang=None, existing_xml=None, element=None, reuse=True):
|
||||||
"""Enable and initialize a stanza plugin.
|
"""Enable and initialize a stanza plugin.
|
||||||
|
|
||||||
:param string attrib: The :attr:`plugin_attrib` value of the
|
:param string attrib: The :attr:`plugin_attrib` value of the
|
||||||
|
@ -504,6 +504,9 @@ class ElementBase(object):
|
||||||
if reuse and (attrib, lang) in self.plugins:
|
if reuse and (attrib, lang) in self.plugins:
|
||||||
return self.plugins[(attrib, lang)]
|
return self.plugins[(attrib, lang)]
|
||||||
|
|
||||||
|
if element is not None:
|
||||||
|
plugin = element
|
||||||
|
else:
|
||||||
plugin = plugin_class(parent=self, xml=existing_xml)
|
plugin = plugin_class(parent=self, xml=existing_xml)
|
||||||
|
|
||||||
if plugin.is_extension:
|
if plugin.is_extension:
|
||||||
|
@ -1172,14 +1175,18 @@ class ElementBase(object):
|
||||||
else:
|
else:
|
||||||
raise TypeError
|
raise TypeError
|
||||||
self.xml.append(item.xml)
|
self.xml.append(item.xml)
|
||||||
self.iterables.append(item)
|
if item.__class__ == self.plugin_tag_map.get(item.tag_name(), None):
|
||||||
if item.__class__ in self.plugin_iterables:
|
|
||||||
if item.__class__.plugin_multi_attrib:
|
|
||||||
self.init_plugin(item.__class__.plugin_multi_attrib)
|
|
||||||
elif item.__class__ == self.plugin_tag_map.get(item.tag_name(), None):
|
|
||||||
self.init_plugin(item.plugin_attrib,
|
self.init_plugin(item.plugin_attrib,
|
||||||
existing_xml=item.xml,
|
existing_xml=item.xml,
|
||||||
|
element=item,
|
||||||
reuse=False)
|
reuse=False)
|
||||||
|
elif item.__class__ in self.plugin_iterables:
|
||||||
|
self.iterables.append(item)
|
||||||
|
if item.__class__.plugin_multi_attrib:
|
||||||
|
self.init_plugin(item.__class__.plugin_multi_attrib)
|
||||||
|
else:
|
||||||
|
self.iterables.append(item)
|
||||||
|
|
||||||
return self
|
return self
|
||||||
|
|
||||||
def appendxml(self, xml):
|
def appendxml(self, xml):
|
||||||
|
@ -1269,14 +1276,14 @@ class ElementBase(object):
|
||||||
|
|
||||||
# Check that this stanza is a superset of the other stanza.
|
# Check that this stanza is a superset of the other stanza.
|
||||||
values = self.values
|
values = self.values
|
||||||
|
other_values = other.values
|
||||||
for key in other.keys():
|
for key in other.keys():
|
||||||
if key not in values or values[key] != other[key]:
|
if key not in values or values.get(key) != other_values.get(key):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
# Check that the other stanza is a superset of this stanza.
|
# Check that the other stanza is a superset of this stanza.
|
||||||
values = other.values
|
|
||||||
for key in self.keys():
|
for key in self.keys():
|
||||||
if key not in values or values[key] != self[key]:
|
if key not in values or other_values.get(key) != values.get(key):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
# Both stanzas are supersets of each other, therefore they
|
# Both stanzas are supersets of each other, therefore they
|
||||||
|
|
Loading…
Reference in a new issue