From f087326373250c76fa3b7b8e68cede0cb9af01ff Mon Sep 17 00:00:00 2001 From: Mark Spruiell Date: Wed, 17 Oct 2012 12:38:03 -0700 Subject: ICE-4619 - custom enumerator values --- py/python/Ice.py | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) (limited to 'py/python/Ice.py') diff --git a/py/python/Ice.py b/py/python/Ice.py index 5790c64cd8a..e371ffe15fa 100644 --- a/py/python/Ice.py +++ b/py/python/Ice.py @@ -189,6 +189,70 @@ class UserException(Exception): '''The base class for all user-defined exceptions.''' pass +class EnumBase(object): + def __init__(self, _n, _v): + self._name = _n + self._value = _v + + def __str__(self): + return self._name + + __repr__ = __str__ + + def __hash__(self): + return self._value + + def __lt__(self, other): + if isinstance(other, self.__class__): + return self._value < other._value; + elif other == None: + return False + return NotImplemented + + def __le__(self, other): + if isinstance(other, self.__class__): + return self._value <= other._value; + elif other == None: + return False + return NotImplemented + + def __eq__(self, other): + if isinstance(other, self.__class__): + return self._value == other._value; + elif other == None: + return False + return NotImplemented + + def __ne__(self, other): + if isinstance(other, self.__class__): + return self._value != other._value; + elif other == None: + return False + return NotImplemented + + def __gt__(self, other): + if isinstance(other, self.__class__): + return self._value > other._value; + elif other == None: + return False + return NotImplemented + + def __ge__(self, other): + if isinstance(other, self.__class__): + return self._value >= other._value; + elif other == None: + return False + return NotImplemented + + def _getName(self): + return self._name + + def _getValue(self): + return self._value + + name = property(_getName) + value = property(_getValue) + class SlicedData(object): # # Members: -- cgit v1.2.3