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:
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):
class BulletDef(object):
"""Bullet definition."""
- direction = None
- speed = None
-
def __init__(self, actions=(), direction=None, speed=None, tags=()):
self.direction = direction
self.speed = speed
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
def __setstate__(self, state):
state = dict(state)
- self.__init__(state["type"], state.get("x"), state.get("y"))
+ x = NumberDef(state["x"]) if "x" in state else None
+ y = NumberDef(state["y"]) if "y" in state else None
+ self.__init__(state["type"], x, y)
@classmethod
def FromXML(cls, doc, element):
)
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