#NEWLINE# def total_ordering( cls ) : #NEWLINE# #INDENT# 'Class decorator that fills in missing ordering methods' #NEWLINE# convert = { #NEWLINE# #INDENT# '__lt__' : [ ( '__gt__' , ( lambda self , other : ( not ( ( self < other ) or ( self == other ) ) ) ) ) , ( '__le__' , ( lambda self , other : ( ( self < other ) or ( self == other ) ) ) ) , ( '__ge__' , ( lambda self , other : ( not ( self < other ) ) ) ) ] , #NEWLINE# '__le__' : [ ( '__ge__' , ( lambda self , other : ( ( not ( self <= other ) ) or ( self == other ) ) ) ) , ( '__lt__' , ( lambda self , other : ( ( self <= other ) and ( not ( self == other ) ) ) ) ) , ( '__gt__' , ( lambda self , other : ( not ( self <= other ) ) ) ) ] , #NEWLINE# '__gt__' : [ ( '__lt__' , ( lambda self , other : ( not ( ( self > other ) or ( self == other ) ) ) ) ) , ( '__ge__' , ( lambda self , other : ( ( self > other ) or ( self == other ) ) ) ) , ( '__le__' , ( lambda self , other : ( not ( self > other ) ) ) ) ] , #NEWLINE# '__ge__' : [ ( '__le__' , ( lambda self , other : ( ( not ( self >= other ) ) or ( self == other ) ) ) ) , ( '__gt__' , ( lambda self , other : ( ( self >= other ) and ( not ( self == other ) ) ) ) ) , ( '__lt__' , ( lambda self , other : ( not ( self >= other ) ) ) ) ] , #NEWLINE# #UNINDENT# } #NEWLINE# roots = ( set ( dir ( cls ) ) & set ( convert ) ) #NEWLINE# if ( not roots ) : #NEWLINE# #INDENT# raise ValueError ( 'must define at least one ordering operation: < > <= >=' ) #NEWLINE# #UNINDENT# root = max ( roots ) #NEWLINE# for ( opname , opfunc ) in convert [ root ] : #NEWLINE# #INDENT# if ( opname not in roots ) : #NEWLINE# #INDENT# opfunc . __name__ = opname #NEWLINE# opfunc . __doc__ = getattr ( int , opname ) . __doc__ #NEWLINE# setattr ( cls , opname , opfunc ) #NEWLINE# #UNINDENT# #UNINDENT# return cls