tree = ElementTree()
root = tree.parse(source)
- self = cls(type=root.get("type", "none"))
+ doc = cls(type=root.get("type", "none"))
- self._bullets = {}
- self._actions = {}
- self._fires = {}
- self._bullet_refs = []
- self._action_refs = []
- self._fire_refs = []
+ doc._bullets = {}
+ doc._actions = {}
+ doc._fires = {}
+ doc._bullet_refs = []
+ doc._action_refs = []
+ doc._fire_refs = []
for element in root.getchildren():
tag = realtag(element)
- if tag in self.CONSTRUCTORS:
- self.CONSTRUCTORS[tag].FromXML(self, element)
+ if tag in doc.CONSTRUCTORS:
+ doc.CONSTRUCTORS[tag].FromXML(doc, element)
try:
- for ref in self._bullet_refs:
- ref.bullet = self._bullets[ref.bullet]
- for ref in self._fire_refs:
- ref.fire = self._fires[ref.fire]
- for ref in self._action_refs:
- ref.action = self._actions[ref.action]
+ for ref in doc._bullet_refs:
+ ref.bullet = doc._bullets[ref.bullet]
+ for ref in doc._fire_refs:
+ ref.fire = doc._fires[ref.fire]
+ for ref in doc._action_refs:
+ ref.action = doc._actions[ref.action]
except KeyError as exc:
raise ParseError("unknown reference %s" % exc)
- self.actions = [act for name, act in self._actions.items()
+ doc.actions = [act for name, act in doc._actions.items()
if name and name.startswith("top")]
- del(self._bullet_refs)
- del(self._action_refs)
- del(self._fire_refs)
- del(self._bullets)
- del(self._actions)
- del(self._fires)
+ del(doc._bullet_refs)
+ del(doc._action_refs)
+ del(doc._fire_refs)
+ del(doc._bullets)
+ del(doc._actions)
+ del(doc._fires)
- return self
+ return doc
@classmethod
def FromYAML(cls, source):