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