From 2c8872de033bd821b6a3ce52b65e609d8016c391 Mon Sep 17 00:00:00 2001 From: Nataliia Uvarova Date: Sun, 15 Jun 2014 11:08:59 +0300 Subject: [PATCH] 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 --- marconi/queues/storage/utils.py | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/marconi/queues/storage/utils.py b/marconi/queues/storage/utils.py index 879f2c85f..69eea69f0 100644 --- a/marconi/queues/storage/utils.py +++ b/marconi/queues/storage/utils.py @@ -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)