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
This commit is contained in:
Cyril Roelandt 2015-06-17 14:25:56 +00:00
parent 3b27f83964
commit 53209ca19a
1 changed files with 3 additions and 2 deletions

View File

@ -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):