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 <doug@doughellmann.com>
This commit is contained in:
Doug Hellmann 2018-06-06 18:47:53 -04:00 committed by Nguyen Hai
parent 4f16ddf347
commit dd54b4881a
1 changed files with 4 additions and 5 deletions

View File

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