19
def check_enum_type(enum):
20
if not issubclass(enum, DBEnumeratedType):
22
'%r must be a DBEnumeratedType: %r' % (enum, type(enum)))
26
if type(enum) in (list, tuple):
27
map(check_enum_type, enum)
19
32
class DBEnumVariable(Variable):
20
33
"""A Storm variable class representing a DBEnumeratedType."""
21
34
__slots__ = ("_enum",)
23
36
def __init__(self, *args, **kwargs):
24
self._enum = kwargs.pop("enum")
25
if not issubclass(self._enum, DBEnumeratedType):
27
'%r must be a DBEnumeratedType: %r'
28
% (self._enum, type(self._enum)))
37
enum = kwargs.pop("enum")
38
if type(enum) not in (list, tuple):
41
check_type(self._enum)
29
42
super(DBEnumVariable, self).__init__(*args, **kwargs)
31
44
def parse_set(self, value, from_db):
33
return self._enum.items[value]
46
for enum in self._enum:
48
return enum.items[value]
51
raise KeyError('%r not in present in any of %r' % (
35
54
if not zope_isinstance(value, DBItem):
36
55
raise TypeError("Not a DBItem: %r" % (value,))
37
if self._enum != value.enum:
38
raise TypeError("DBItem from wrong type, %r != %r" % (
39
self._enum.name, value.enum.name))
56
if value.enum not in self._enum:
57
raise TypeError("DBItem from unknown enum, %r not in %r" % (
58
value.enum.name, self._enum))
42
61
def parse_get(self, value, to_db):
56
75
enum = kw.pop('enum')
58
77
enum = kw.pop('schema')
59
if not issubclass(enum, DBEnumeratedType):
61
'%r must be a DBEnumeratedType: %r' % (enum, type(enum)))
65
82
super(DBSchemaEnumCol, self).__init__(**kw)
68
85
EnumCol = DBSchemaEnumCol