From: Joe Guo Date: Tue, 10 Apr 2018 02:51:37 +0000 (+1200) Subject: kcc: fix sort for py3 X-Git-Tag: ldb-1.4.0~584 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=c7f3c91b62c3f8f2bb44fc23bf65710e4b290105;p=thirdparty%2Fsamba.git kcc: fix sort for py3 py2: list.sort(cmp=None, key=None, reverse=False) sorted(iterable[, cmp[, key[, reverse]]]) py3: list.sort(key=None, reverse=False) sorted(iterable, *, key=None, reverse=False) The `cmp` arg was removed in py3, make use of `key` arg to work around. Signed-off-by: Joe Guo Reviewed-by: Andrew Bartlett Reviewed-by: Douglas Bagnall --- diff --git a/python/samba/kcc/__init__.py b/python/samba/kcc/__init__.py index f0046630fcf..1a962bb03c1 100644 --- a/python/samba/kcc/__init__.py +++ b/python/samba/kcc/__init__.py @@ -46,18 +46,6 @@ from samba.kcc.debug import DEBUG, DEBUG_FN, logger from samba.kcc import debug -def sort_replica_by_dsa_guid(rep1, rep2): - """Helper to sort NCReplicas by their DSA guids - - The guids need to be sorted in their NDR form. - - :param rep1: An NC replica - :param rep2: Another replica - :return: -1, 0, or 1, indicating sort order. - """ - return cmp(ndr_pack(rep1.rep_dsa_guid), ndr_pack(rep2.rep_dsa_guid)) - - def sort_dsa_by_gc_and_guid(dsa1, dsa2): """Helper to sort DSAs by guid global catalog status @@ -2194,7 +2182,7 @@ class KCC(object): # on the local DC r_list.append(l_of_x) - r_list.sort(sort_replica_by_dsa_guid) + r_list.sort(key=lambda rep: ndr_pack(rep.rep_dsa_guid)) r_len = len(r_list) max_node_edges = self.intrasite_max_node_edges(r_len) diff --git a/python/samba/kcc/kcc_utils.py b/python/samba/kcc/kcc_utils.py index 6e15c0b1e31..2118570bbfc 100644 --- a/python/samba/kcc/kcc_utils.py +++ b/python/samba/kcc/kcc_utils.py @@ -1581,7 +1581,9 @@ class Site(object): # Which is a fancy way of saying "sort all the nTDSDSA objects # in the site by guid in ascending order". Place sorted list # in D_sort[] - D_sort = sorted(self.rw_dsa_table.values(), cmp=sort_dsa_by_guid) + D_sort = sorted( + self.rw_dsa_table.values(), + key=lambda dsa: ndr_pack(dsa.dsa_guid)) # double word number of 100 nanosecond intervals since 1600s @@ -2221,11 +2223,6 @@ def get_dsa_config_rep(dsa): dsa.dsa_dnstr) -def sort_dsa_by_guid(dsa1, dsa2): - "use ndr_pack for GUID comparison, as appears correct in some places""" - return cmp(ndr_pack(dsa1.dsa_guid), ndr_pack(dsa2.dsa_guid)) - - def new_connection_schedule(): """Create a default schedule for an NTDSConnection or Sitelink. This is packed differently from the repltimes schedule used elsewhere