From 854aaf4986cd79b659fe4de0b1d319dbd5f9ac92 Mon Sep 17 00:00:00 2001 From: "Chris St. Pierre" Date: Mon, 20 Aug 2012 13:40:29 -0400 Subject: added CmpMixin to provide __cmp__ functionality to py3k --- src/lib/Bcfg2/Bcfg2Py3k.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'src/lib/Bcfg2/Bcfg2Py3k.py') diff --git a/src/lib/Bcfg2/Bcfg2Py3k.py b/src/lib/Bcfg2/Bcfg2Py3k.py index 7fce94789..784ac118f 100644 --- a/src/lib/Bcfg2/Bcfg2Py3k.py +++ b/src/lib/Bcfg2/Bcfg2Py3k.py @@ -92,3 +92,25 @@ try: from collections import MutableMapping except ImportError: from UserDict import DictMixin as MutableMapping + + +# in py3k __cmp__ is no longer magical, so we define a mixin that can +# be used to define the rich comparison operators from __cmp__ +class CmpMixin(object): + def __lt__(self, other): + return self.__cmp__(other) < 0 + + def __gt__(self, other): + return self.__cmp__(other) > 0 + + def __eq__(self, other): + return self.__cmp__(other) == 0 + + def __ne__(self, other): + return not self.__eq__(other) + + def __ge__(self, other): + return self.__gt__(other) or self.__eq__(other) + + def __le__(self, other): + return self.__lt__(other) or self.__eq__(other) -- cgit v1.2.3-1-g7c22