<s> import types , string , exceptions <EOL> class EnumException ( exceptions . Exception ) : <EOL> pass <EOL> class Enumeration : <EOL> def __init__ ( self , name , enumList ) : <EOL> self . __doc__ = name <EOL> lookup = { } <EOL> reverseLookup = { } <EOL> i = <NUM_LIT:0> <EOL> uniqueNames = [ ] <EOL> uniqueValues = [ ] <EOL> for x in enumList : <EOL> if type ( x ) == types . TupleType : <EOL> x , i = x <EOL> if type ( x ) != types . StringType : <EOL> raise EnumException , "<STR_LIT>" + x <EOL> if type ( i ) != types . IntType : <EOL> raise EnumException , "<STR_LIT>" + i <EOL> if x in uniqueNames : <EOL> raise EnumException , "<STR_LIT>" + x <EOL> if i in uniqueValues : <EOL> raise EnumException , "<STR_LIT>" + x <EOL> uniqueNames . append ( x ) <EOL> uniqueValues . append ( i ) <EOL> lookup [ x ] = i <EOL> reverseLookup [ i ] = x <EOL> i = i + <NUM_LIT:1> <EOL> self . lookup = lookup <EOL> self . reverseLookup = reverseLookup <EOL> def __getattr__ ( self , attr ) : <EOL> if not self . lookup . has_key ( attr ) : <EOL> raise AttributeError <EOL> return self . lookup [ attr ] <EOL> def whatis ( self , value ) : <EOL> return self . reverseLookup [ value ] </s>
