from xml.etree.ElementTree import ElementTree
+# Python 3 moved this for no really good reason.
+try:
+ from sys import intern
+except ImportError:
+ pass
+
try:
from io import StringIO
except ImportError:
from bulletml.expr import NumberDef, INumberDef
-__all_ = ["ParseError", "BulletML"]
+__all__ = ["ParseError", "BulletML"]
class ParseError(Error):
"""Raised when an error occurs parsing the XML structure."""
def __init__(self, type, value):
if type not in self.VALID_TYPES:
raise ValueError("invalid type %r" % type)
- self.type = type
+ self.type = intern(type)
self.value = value
def __getstate__(self):
def __init__(self, type, value):
if type not in self.VALID_TYPES:
raise ValueError("invalid type %r" % type)
- self.type = type
+ self.type = intern(type)
self.value = value
def __getstate__(self):
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)
actions = []
speed = None
direction = None
+ tags = set()
for subelem in element.getchildren():
tag = realtag(subelem)
if tag == "direction":
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
def __init__(self, type, x, y):
if type not in self.VALID_TYPES:
raise ValueError("invalid type %r" % type)
- self.type = type
+ self.type = intern(type)
self.x = x
self.y = y
direction = None
speed = None
offset = None
+ tags = set()
for subelem in element.getchildren():
tag = realtag(subelem)
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:
)
def __init__(self, type="none", actions=None):
- self.type = type
+ self.type = intern(type)
self.actions = [] if actions is None else actions
def __getstate__(self):
else:
try:
return yaml.load(source)
- except Exception, exc:
+ except Exception as exc:
raise ParseError(str(exc))
@classmethod