summaryrefslogtreecommitdiff
path: root/python/samba/common.py
diff options
context:
space:
mode:
authorJoe Guo <joeg@catalyst.net.nz>2018-03-26 17:07:33 +1300
committerAndrew Bartlett <abartlet@samba.org>2018-04-05 08:59:10 +0200
commit0ebf52744c5171d4eb5f0b0616d3880d7bbd9db4 (patch)
treee2337d1404b83e2dd53d003845528be4f90e349f /python/samba/common.py
parent80aaafc2ce96b3b18ae66d37cdb70cc731edb6e5 (diff)
downloadsamba-0ebf52744c5171d4eb5f0b0616d3880d7bbd9db4.tar.gz
selftest: enable py3 for samba.tests.common
fix dsdb_Dn comparison for Python 3 In Python 3, the builtin `cmp` funtion was dropped. And the `__cmp__` magic method in object is no longer honored, which is replaced by 6 new methods: __eq__, __ne__, __lt__, __le__, __gt__, __ge__. This caused `tests.CommonTests` failed with `py3_compatiable=True`. Fixed by adding the above methods. Signed-off-by: Joe Guo <joeg@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org> Reviewed-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
Diffstat (limited to 'python/samba/common.py')
-rw-r--r--python/samba/common.py27
1 files changed, 27 insertions, 0 deletions
diff --git a/python/samba/common.py b/python/samba/common.py
index 1c410a4702d..66003993730 100644
--- a/python/samba/common.py
+++ b/python/samba/common.py
@@ -23,6 +23,14 @@ from samba.ndr import ndr_pack
from samba.dcerpc import misc
import binascii
+from samba.compat import PY3
+
+
+if PY3:
+ # cmp() exists only in Python 2
+ def cmp(a, b):
+ return (a > b) - (a < b)
+
def confirm(msg, forced=False, allow_all=False):
"""confirm an action with the user
@@ -110,6 +118,25 @@ class dsdb_Dn(object):
v = cmp(dn1.binary, dn2.binary)
return v
+ # In Python3, __cmp__ is replaced by these 6 methods
+ def __eq__(self, other):
+ return self.__cmp__(other) == 0
+
+ def __ne__(self, other):
+ return self.__cmp__(other) != 0
+
+ def __lt__(self, other):
+ return self.__cmp__(other) < 0
+
+ def __le__(self, other):
+ return self.__cmp__(other) <= 0
+
+ def __gt__(self, other):
+ return self.__cmp__(other) > 0
+
+ def __ge__(self, other):
+ return self.__cmp__(other) >= 0
+
def get_binary_integer(self):
'''return binary part of a dsdb_Dn as an integer, or None'''
if self.prefix == '':