Make storage.utils.keyify py3k compatible

In the storage.utils.keyify function, there is proxy object, that wraps
each item and makes it comparable via __cmp__ function. Since Python 3
old-fashion `cmp` is totally removed and only rich comparison functions
should be used (i.e. __lt__, __gt__).

Partially-implements: blueprint py3k-support
Change-Id: I36841fa33c7e49b8b14fb623d6859077e3d8b6f5
This commit is contained in:
Nataliia Uvarova 2014-06-15 11:08:59 +03:00
parent 83423b96eb
commit 2c8872de03

View File

@ -97,11 +97,23 @@ def keyify(key, iterable):
def __init__(self, obj):
self.obj = obj
def __cmp__(self, other):
return cmp(self.obj[key], other.obj[key])
def __eq__(self, other):
return self.obj[key] == other.obj[key]
# TODO(zyuan): define magic operators to make py3 work
# http://code.activestate.com/recipes/576653/
def __ne__(self, other):
return self.obj[key] != other.obj[key]
def __lt__(self, other):
return self.obj[key] < other.obj[key]
def __le__(self, other):
return self.obj[key] <= other.obj[key]
def __gt__(self, other):
return self.obj[key] > other.obj[key]
def __ge__(self, other):
return self.obj[key] >= other.obj[key]
for item in iterable:
yield Keyed(item)