From dd54b4881a9df50175da834ea0a01c0e6fe87184 Mon Sep 17 00:00:00 2001 From: Doug Hellmann Date: Wed, 6 Jun 2018 18:47:53 -0400 Subject: [PATCH] replace cmp with total_ordering decorator The cmp() built-in is no longer available under python 3 and the __cmp__ method is not used. Remove __cmp__ and __ne__ and add a __lt__ method and use the functools.total_ordering decorator to provide all of the rich comparison methods for StoreLocations. Change-Id: Iae1d0c27bd82a42c80fc98f87c9b85edef527c51 Signed-off-by: Doug Hellmann --- glance/location.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/glance/location.py b/glance/location.py index 8e62da46f9..bde3b1355b 100644 --- a/glance/location.py +++ b/glance/location.py @@ -15,6 +15,7 @@ import collections import copy +import functools from cryptography import exceptions as crypto_exception from cursive import exception as cursive_exception @@ -158,6 +159,7 @@ class ImageFactoryProxy(glance.domain.proxy.ImageFactory): return super(ImageFactoryProxy, self).new_image(**kwargs) +@functools.total_ordering class StoreLocations(collections.MutableSequence): """ The proxy for store location property. It takes responsibility for:: @@ -297,14 +299,11 @@ class StoreLocations(collections.MutableSequence): else: return other - def __cmp__(self, other): - return cmp(self.value, self.__cast(other)) - def __eq__(self, other): return self.value == self.__cast(other) - def __ne__(self, other): - return not self.__eq__(other) + def __lt__(self, other): + return self.value < self.__cast(other) def __iter__(self): return iter(self.value)