From 29947fe1a304ff6f913e5d94d56d8108a7c94087 Mon Sep 17 00:00:00 2001 From: Christian Heimes Date: Fri, 18 Nov 2016 12:24:09 +0100 Subject: 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 Reviewed-By: Martin Basti --- ipaplatform/redhat/tasks.py | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) (limited to 'ipaplatform') diff --git a/ipaplatform/redhat/tasks.py b/ipaplatform/redhat/tasks.py index dbe005abb..5d627becf 100644 --- a/ipaplatform/redhat/tasks.py +++ b/ipaplatform/redhat/tasks.py @@ -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): -- cgit