"""For Python < 2.7.2. total_ordering in versions prior to 2.7.2 is buggy.See http://bugs.python.org/issue10042 for details. For these versions usecode borrowed from Python 2.7.3.From django.utils."""importsysifsys.version_info>=(2,7,2):fromfunctoolsimporttotal_orderingelse:deftotal_ordering(cls):"""Class decorator that fills in missing ordering methods"""convert={'__lt__':[('__gt__',lambdaself,other:not(self<otherorself==other)),('__le__',lambdaself,other:self<otherorself==other),('__ge__',lambdaself,other:notself<other)],'__le__':[('__ge__',lambdaself,other:notself<=otherorself==other),('__lt__',lambdaself,other:self<=otherandnotself==other),('__gt__',lambdaself,other:notself<=other)],'__gt__':[('__lt__',lambdaself,other:not(self>otherorself==other)),('__ge__',lambdaself,other:self>otherorself==other),('__le__',lambdaself,other:notself>other)],'__ge__':[('__le__',lambdaself,other:(notself>=other)orself==other),('__gt__',lambdaself,other:self>=otherandnotself==other),('__lt__',lambdaself,other:notself>=other)]}roots=set(dir(cls))&set(convert)ifnotroots:raiseValueError('must define at least one ordering operation: < > <= >=')root=max(roots)# prefer __lt__ to __le__ to __gt__ to __ge__foropname,opfuncinconvert[root]:ifopnamenotinroots:opfunc.__name__=opnameopfunc.__doc__=getattr(int,opname).__doc__setattr(cls,opname,opfunc)returncls