mirror of
https://github.com/correl/SleekXMPP.git
synced 2024-11-30 19:19:55 +00:00
Updated ElementBase.__init__
This commit is contained in:
parent
747001d33c
commit
415520200e
1 changed files with 29 additions and 17 deletions
|
@ -45,25 +45,37 @@ class ElementBase(object):
|
||||||
subitem = None
|
subitem = None
|
||||||
|
|
||||||
def __init__(self, xml=None, parent=None):
|
def __init__(self, xml=None, parent=None):
|
||||||
if parent is None:
|
"""
|
||||||
self.parent = None
|
Create a new stanza object.
|
||||||
else:
|
|
||||||
self.parent = weakref.ref(parent)
|
Arguments:
|
||||||
|
xml -- Initialize the stanza with optional existing XML.
|
||||||
|
parent -- Optional stanza object that contains this stanza.
|
||||||
|
"""
|
||||||
self.xml = xml
|
self.xml = xml
|
||||||
self.plugins = {}
|
self.plugins = {}
|
||||||
self.iterables = []
|
self.iterables = []
|
||||||
self.idx = 0
|
self.idx = 0
|
||||||
if not self.setup(xml):
|
if parent is None:
|
||||||
|
self.parent = None
|
||||||
|
else:
|
||||||
|
self.parent = weakref.ref(parent)
|
||||||
|
|
||||||
|
if self.setup(xml):
|
||||||
|
# If we generated our own XML, then everything is ready.
|
||||||
|
return
|
||||||
|
|
||||||
|
# Initialize values using provided XML
|
||||||
for child in self.xml.getchildren():
|
for child in self.xml.getchildren():
|
||||||
if child.tag in self.plugin_tag_map:
|
if child.tag in self.plugin_tag_map:
|
||||||
self.plugins[self.plugin_tag_map[child.tag].plugin_attrib] = self.plugin_tag_map[child.tag](xml=child, parent=self)
|
plugin = self.plugin_tag_map[child.tag]
|
||||||
|
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:
|
||||||
if child.tag == "{%s}%s" % (sub.namespace, sub.name):
|
if child.tag == "{%s}%s" % (sub.namespace, sub.name):
|
||||||
self.iterables.append(sub(xml=child, parent=self))
|
self.iterables.append(sub(child, self))
|
||||||
break
|
break
|
||||||
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def attrib(self): #backwards compatibility
|
def attrib(self): #backwards compatibility
|
||||||
return self
|
return self
|
||||||
|
|
Loading…
Reference in a new issue