Add back missing compat module

This commit is contained in:
Ben Firshman 2014-01-11 14:31:56 +00:00
parent 0614e2c590
commit d063f0e00c
3 changed files with 24 additions and 1 deletions

0
fig/compat/__init__.py Normal file
View File

23
fig/compat/functools.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

View File

@ -2,7 +2,7 @@ from __future__ import unicode_literals
from __future__ import absolute_import
import logging
from .service import Service
from .compat import cmp_to_key
from .compat.functools import cmp_to_key
log = logging.getLogger(__name__)