Browse Source

Add back missing compat module

Ben Firshman 12 years ago
parent
commit
d063f0e00c
3 changed files with 24 additions and 1 deletions
  1. 0 0
      fig/compat/__init__.py
  2. 23 0
      fig/compat/functools.py
  3. 1 1
      fig/project.py

+ 0 - 0
fig/compat/__init__.py


+ 23 - 0
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
+

+ 1 - 1
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__)