def total_ordering(cls):
convert = {<EOL>'<STR_LIT>': [<EOL>(<EOL>'<STR_LIT>',<EOL>lambda self, other: not (self < other or self == other)<EOL>),<EOL>(<EOL>'<STR_LIT>',<EOL>lambda self, other: self < other or self == other<EOL>),<EOL>(<EOL>'<STR_LIT>',<EOL>lambda self, other: not self < other<EOL>)],<EOL>'<STR_LIT>': [<EOL>(<EOL>'<STR_LIT>',<EOL>lambda self, other: not self <= other or self == other<EOL>),<EOL>(<EOL>'<STR_LIT>',<EOL>lambda self, other: self <= other and not self == other<EOL>),<EOL>(<EOL>'<STR_LIT>',<EOL>lambda self, other: not self <= other<EOL>)],<EOL>'<STR_LIT>': [<EOL>(<EOL>'<STR_LIT>',<EOL>lambda self, other: not (self > other or self == other)<EOL>),<EOL>(<EOL>'<STR_LIT>',<EOL>lambda self, other: self > other or self == other<EOL>),<EOL>(<EOL>'<STR_LIT>',<EOL>lambda self, other: not self > other<EOL>)],<EOL>'<STR_LIT>': [<EOL>(<EOL>'<STR_LIT>',<EOL>lambda self, other: (not self >= other) or self == other<EOL>),<EOL>(<EOL>'<STR_LIT>',<EOL>lambda self, other: self >= other and not self == other<EOL>),<EOL>(<EOL>'<STR_LIT>',<EOL>lambda self, other: not self >= other<EOL>)]<EOL>}<EOL>roots = set(dir(cls)) & set(convert)<EOL>if not roots:<EOL><INDENT>raise ValueError(<EOL>'<STR_LIT>'<EOL>)<EOL><DEDENT>root = max(roots)  <EOL>for opname, opfunc in convert[root]:<EOL><INDENT>if opname not in roots:<EOL><INDENT>opfunc.__name__ = opname<EOL>opfunc.__doc__ = getattr(int, opname).__doc__<EOL>setattr(cls, opname, opfunc)<EOL><DEDENT><DEDENT>return cls<EOL>
Backport to work with Python 2.6
Class decorator that fills in missing ordering methods
Code from: http://code.activestate.com/recipes/576685/