X-Git-Url: https://git.yukkurigames.com/?p=python-bulletml.git;a=blobdiff_plain;f=bulletml%2Fparser.py;h=b2e078b739a5153596f91fbb0af1c59ffd4aad3b;hp=8f253fe7a09d722ebded8d296d4c8f0a9d64def6;hb=bc6dd530488535b2edeff9afbbdde896aed73046;hpb=6e7423671150b704dd2accbf4b8d544744271b81 diff --git a/bulletml/parser.py b/bulletml/parser.py index 8f253fe..b2e078b 100644 --- a/bulletml/parser.py +++ b/bulletml/parser.py @@ -25,7 +25,7 @@ from bulletml.errors import Error from bulletml.expr import NumberDef, INumberDef -__all_ = ["ParseError", "BulletML"] +__all__ = ["ParseError", "BulletML"] class ParseError(Error): """Raised when an error occurs parsing the XML structure.""" @@ -358,7 +358,7 @@ class BulletDef(object): direction = None speed = None - def __init__(self, actions=[], direction=None, speed=None, tags=()): + def __init__(self, actions=(), direction=None, speed=None, tags=()): self.direction = direction self.speed = speed self.actions = list(actions) @@ -386,6 +386,7 @@ class BulletDef(object): actions = [] speed = None direction = None + tags = set() for subelem in element.getchildren(): tag = realtag(subelem) if tag == "direction": @@ -397,8 +398,8 @@ class BulletDef(object): elif tag == "actionRef": actions.append(ActionRef.FromXML(doc, subelem)) elif tag == "tag": - self.tags.add(subelem.text) - dfn = cls(actions, direction, speed) + tags.add(subelem.text) + dfn = cls(actions, direction, speed, tags) doc._bullets[element.get("label")] = dfn return dfn @@ -613,6 +614,7 @@ class FireDef(object): direction = None speed = None offset = None + tags = set() for subelem in element.getchildren(): tag = realtag(subelem) @@ -627,9 +629,9 @@ class FireDef(object): elif tag == "offset": offset = Offset.FromXML(doc, subelem) elif tag == "tag": - self.tags.add(subelem.text) + tags.add(subelem.text) try: - fire = cls(bullet, direction, speed, offset) + fire = cls(bullet, direction, speed, offset, tags) except UnboundLocalError as exc: raise ParseError(str(exc)) else: