summaryrefslogtreecommitdiffstats
path: root/ipaplatform
diff options
context:
space:
mode:
authorChristian Heimes <cheimes@redhat.com>2016-11-18 12:24:09 +0100
committerMartin Basti <mbasti@redhat.com>2016-11-22 17:44:27 +0100
commit29947fe1a304ff6f913e5d94d56d8108a7c94087 (patch)
tree02c5635057ac0850e1c0308eefdf0ee6132f6fb6 /ipaplatform
parent55b14abcb561422cf48755dae6b0638656535fe5 (diff)
downloadfreeipa-29947fe1a304ff6f913e5d94d56d8108a7c94087.tar.gz
freeipa-29947fe1a304ff6f913e5d94d56d8108a7c94087.tar.xz
freeipa-29947fe1a304ff6f913e5d94d56d8108a7c94087.zip
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>
Diffstat (limited to 'ipaplatform')
-rw-r--r--ipaplatform/redhat/tasks.py16
1 files changed, 11 insertions, 5 deletions
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):