MCPcopy Create free account
hub / github.com/ActiveState/code / EnumValue

Class EnumValue

recipes/Python/577482_Easy_property/recipe-577482.py:94–110  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

92 def __str__(self): return 'enum ' + str(constants)
93
94 class EnumValue(object):
95 __slots__ = ('__value')
96 def __init__(self, value): self.__value = value
97 value = property(lambda self: self.__value)
98 type = property(lambda self: EnumType)
99 def __hash__(self): return hash(self.__value)
100 def __cmp__(self, other):
101 try:
102 if self.type is other.type:
103 return cmp(self.__value, other.__value)
104 else:
105 raise TypeError, "requires a '%s' object but received a '%s'" % ( self.type.__class__.__name__, other.type.__class__.__name__ )
106 except AttributeError:
107 raise TypeError, "requires a '%s' object but received a '%s'" % ( self.type.__class__.__name__, other.__class__.__name__ )
108 def __invert__(self): return constants[maximum - self.__value]
109 def __nonzero__(self): return bool(self.__value)
110 def __repr__(self): return str(names[self.__value])
111
112 maximum = len(names) - 1
113 constants = [None] * len(names)

Callers 5

recipe-577439.pyFile · 0.50
GetExtensionInfoFunction · 0.50
recipe-66011.pyFile · 0.50
readRegKeyMethod · 0.50
writeRegKeyMethod · 0.50

Calls

no outgoing calls

Tested by

no test coverage detected