X-Git-Url: https://git.yukkurigames.com/?p=python-bulletml.git;a=blobdiff_plain;f=bulletml%2Fparser.py;h=5435925f753c2c324fe935abf89eb23fdaa69e27;hp=86dfe3c8700c771728cfcdab60ff92953c6a278e;hb=781dc628702361a759834ca5fdf117679d33f76a;hpb=43c03b517877aef0df8eb909d23109e401532cb5 diff --git a/bulletml/parser.py b/bulletml/parser.py index 86dfe3c..5435925 100644 --- a/bulletml/parser.py +++ b/bulletml/parser.py @@ -13,6 +13,12 @@ import math 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: @@ -64,7 +70,7 @@ class Direction(object): 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): @@ -132,7 +138,7 @@ class Speed(object): 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): @@ -355,9 +361,6 @@ class Accel(object): class BulletDef(object): """Bullet definition.""" - direction = None - speed = None - def __init__(self, actions=(), direction=None, speed=None, tags=()): self.direction = direction self.speed = speed @@ -537,7 +540,7 @@ class Offset(object): 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 @@ -551,7 +554,9 @@ class Offset(object): 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): @@ -706,7 +711,7 @@ class BulletML(object): ) 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):