From 53209ca19ac2116d293b6fbc7b31254cb27a3ecb Mon Sep 17 00:00:00 2001 From: Cyril Roelandt Date: Wed, 17 Jun 2015 14:25:56 +0000 Subject: [PATCH] Python 3: do not use cmp(), nor sorted(..., cmp=...) * The "cmp" function has been removed, so we must not use it any more; * The "cmp" keyword argument of the "sorted" function has been removed, so replace it with "key=functool.cmp_to_key". Change-Id: Ic39d29dc1002a68f36f04c32e53a36bc826dce78 Blueprint: neutron-python3 --- neutron/api/api_common.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/neutron/api/api_common.py b/neutron/api/api_common.py index e8a310247..7c062cd6d 100644 --- a/neutron/api/api_common.py +++ b/neutron/api/api_common.py @@ -13,6 +13,7 @@ # License for the specific language governing permissions and limitations # under the License. +import functools import urllib from oslo_config import cfg @@ -272,11 +273,11 @@ class SortingEmulatedHelper(SortingHelper): def sort(self, items): def cmp_func(obj1, obj2): for key, direction in self.sort_dict: - ret = cmp(obj1[key], obj2[key]) + ret = (obj1[key] > obj2[key]) - (obj1[key] < obj2[key]) if ret: return ret * (1 if direction else -1) return 0 - return sorted(items, cmp=cmp_func) + return sorted(items, key=functools.cmp_to_key(cmp_func)) class SortingNativeHelper(SortingHelper): -- 2.45.2