From d063f0e00c28331f2397ea80eea42681594cedc9 Mon Sep 17 00:00:00 2001 From: Ben Firshman Date: Sat, 11 Jan 2014 14:31:56 +0000 Subject: [PATCH] Add back missing compat module --- fig/compat/__init__.py | 0 fig/compat/functools.py | 23 +++++++++++++++++++++++ fig/project.py | 2 +- 3 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 fig/compat/__init__.py create mode 100644 fig/compat/functools.py diff --git a/fig/compat/__init__.py b/fig/compat/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/fig/compat/functools.py b/fig/compat/functools.py new file mode 100644 index 000000000..38a48c334 --- /dev/null +++ b/fig/compat/functools.py @@ -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 + diff --git a/fig/project.py b/fig/project.py index 3c536ab6d..7c05b2c73 100644 --- a/fig/project.py +++ b/fig/project.py @@ -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__)