def __setattr__(self, key, value):
if key != "<STR_LIT:type>":<EOL><INDENT>raise KeyError("<STR_LIT>"%(key))<EOL><DEDENT>allowed = type(self).ALLOWED_TYPES<EOL>if value == None and value in allowed: <EOL><INDENT>super(RestrictedType, self).__setattr__(key, value)<EOL>return<EOL><DEDENT>result = []<EOL>if isinstance(allowed, dict):<EOL><INDENT>for k, v in iteritems(allowed):<EOL><INDENT>if value != k and value != v: continue<EOL>result.append(MultiType(k, v))<EOL><DEDENT><DEDENT>elif isinstance(allowed, list):<EOL><INDENT>result = [v for v in allowed if value == v]<EOL><DEDENT>if len(result) == <NUM_LIT:0>:<EOL><INDENT>raise ValueError("<STR_LIT>""<STR_LIT:%s>"%(value, type(value), type(self), list(allowed)))<EOL><DEDENT>elif len(result) > <NUM_LIT:1>:<EOL><INDENT>raise ValueError("<STR_LIT>""<STR_LIT>"%(value, type(value), result))<EOL><DEDENT>value = result.pop() <EOL>super(RestrictedType, self).__setattr__(key, value)<EOL>
specifically restrict key and value as defined by ALLOWED_TYPES