def Enum(*args, **kwargs):
 def getLabel(cls, val):
  ' Get a string label for the current value of the enum '
  return cls.__labels[val]
 def validate(cls, val):
  ' Returns True if val is a valid value for the enumeration '
  return (val in cls.__values)
 def getValues(cls):
  ' Returns a list of all the possible values for this enum '
  return list(cls.__values)
 def getLabels(cls):
  ' Returns a list of all possible labels for this enum '
  return list(cls.__labels.values())
 def getValue(cls, label):
  ' Returns value given a label '
  return cls.__labels[label]
 for arg in (list(args) + kwargs.keys()):
  if (type(arg) is not str):
   raise TypeError('Enum arg {0} must be a string'.format(arg))
  if (not __isidentifier(arg)):
   raise ValueError("Invalid enum value '{0}'. '{0}' is not a valid identifier".format(arg))
 kwargs.update(zip(args, args))
 newType = type('Enum', (object,), kwargs)
 newType.__labels = dict(((v, k) for (k, v) in kwargs.iteritems()))
 newType.__values = set(newType.__labels.keys())
 newType.getLabel = functools.partial(getLabel, newType)
 newType.validate = functools.partial(validate, newType)
 newType.getValues = functools.partial(getValues, newType)
 newType.getLabels = functools.partial(getLabels, newType)
 newType.getValue = functools.partial(getValue, newType)
 return newType

def Enum ( * args , ** kwargs ) : def getLabel ( cls , val ) : return cls . __labels [ val ] def validate ( cls , val ) : return ( val in cls . __values ) def getValues ( cls ) : return list ( cls . __values ) def getLabels ( cls ) : return list ( cls . __labels . values ( ) ) def getValue ( cls , label ) : return cls . __labels [ label ] for arg in ( list ( args ) + kwargs . keys ( ) ) : if ( type ( arg ) is not str ) : raise TypeError ( 'Enum arg {0} must be a string' . format ( arg ) ) if ( not __isidentifier ( arg ) ) : raise ValueError ( "Invalid enum value '{0}'. '{0}' is not a valid identifier" . format ( arg ) ) kwargs . update ( zip ( args , args ) ) newType = type ( 'Enum' , ( object , ) , kwargs ) newType . __labels = dict ( ( ( v , k ) for ( k , v ) in kwargs . iteritems ( ) ) ) newType . __values = set ( newType . __labels . keys ( ) ) newType . getLabel = functools . partial ( getLabel , newType ) newType . validate = functools . partial ( validate , newType ) newType . getValues = functools . partial ( getValues , newType ) newType . getLabels = functools . partial ( getLabels , newType ) newType . getValue = functools . partial ( getValue , newType ) return newType
enum is an adapter to another field: it will just change its display attribute .