Add texttable compat module that is py3k compatible

This commit is contained in:
Christopher Grebs 2014-01-05 19:13:41 -08:00 • committed by Ben Firshman
commit c6e91db32f
4 changed files with 581 additions and 2 deletions

23
fig/compat/__init__.py Normal file
View file

@ -0,0 +1,23 @@
# Taken from python2.7/3.3 functools
def cmp_to_key(mycmp):
"""Convert a cmp= function into a key= function"""
class K(object):
__slots__ = ['obj']
def __init__(self, obj):
self.obj = obj
def __lt__(self, other):
return mycmp(self.obj, other.obj) < 0
def __gt__(self, other):
return mycmp(self.obj, other.obj) > 0
def __eq__(self, other):
return mycmp(self.obj, other.obj) == 0
def __le__(self, other):
return mycmp(self.obj, other.obj) <= 0
def __ge__(self, other):
return mycmp(self.obj, other.obj) >= 0
def __ne__(self, other):
return mycmp(self.obj, other.obj) != 0
__hash__ = None
return K