def __init__(self, choices, pname=None, **kw): Integer.__init__(self, pname, **kw) self.choices = choices t = type(choices) if isinstance(choices, _seqtypes): self.choices = tuple(choices) elif TypeCode.typechecks: raise TypeError( 'Enumeration choices must be list or sequence, not ' + str(t)) if TypeCode.typechecks: for c in self.choices: if not isinstance(c, _inttypes): raise TypeError('Enumeration choice "' + str(c) + '" is not an integer')
def parse(self, elt, ps): val = Integer.parse(self, elt, ps) if val not in self.choices: raise EvaluateException('Value "' + str(val) + \ '" not in enumeration list', ps.Backtrace(elt)) return val
def serialize(self, elt, sw, pyobj, name=None, orig=None, **kw): if pyobj not in self.choices: raise EvaluateException('Value not in int enumeration list') Integer.serialize(self, elt, sw, pyobj, name=name, orig=orig, **kw)