mirror of
https://salsa.debian.org/freeipa-team/freeipa.git
synced 2025-02-25 18:55:28 -06:00
Minor fixes for IPAVersion class
Py3: classes with __eq__ must provide __hash__ function or set __hash__ to None. Comparison function like __eq__ must signal unsupported types by returning NotImplemented. Python turns this in a proper TypeError. Make the version member read-only and cache _bytes represention. https://fedorahosted.org/freeipa/ticket/6473 Signed-off-by: Christian Heimes <cheimes@redhat.com> Reviewed-By: Martin Basti <mbasti@redhat.com>
This commit is contained in:
committed by
Martin Basti
parent
55b14abcb5
commit
29947fe1a3
@@ -83,20 +83,26 @@ def selinux_enabled():
|
||||
class IPAVersion(object):
|
||||
|
||||
def __init__(self, version):
|
||||
self.version = version
|
||||
self._version = version
|
||||
self._bytes = version.encode('utf-8')
|
||||
|
||||
@property
|
||||
def _bytes(self):
|
||||
return self.version.encode('utf-8')
|
||||
def version(self):
|
||||
return self._version
|
||||
|
||||
def __eq__(self, other):
|
||||
assert isinstance(other, IPAVersion)
|
||||
if not isinstance(other, IPAVersion):
|
||||
return NotImplemented
|
||||
return _librpm.rpmvercmp(self._bytes, other._bytes) == 0
|
||||
|
||||
def __lt__(self, other):
|
||||
assert isinstance(other, IPAVersion)
|
||||
if not isinstance(other, IPAVersion):
|
||||
return NotImplemented
|
||||
return _librpm.rpmvercmp(self._bytes, other._bytes) < 0
|
||||
|
||||
def __hash__(self):
|
||||
return hash(self._version)
|
||||
|
||||
|
||||
class RedHatTaskNamespace(BaseTaskNamespace):
|
||||
|
||||
|
||||
Reference in New Issue
Block a user