From: Cyril Roelandt Date: Wed, 17 Jun 2015 14:25:56 +0000 (+0000) Subject: Python 3: do not use cmp(), nor sorted(..., cmp=...) X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=53209ca19ac2116d293b6fbc7b31254cb27a3ecb;p=openstack-build%2Fneutron-build.git 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 --- 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):