]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
python2 reduction: Merge remaining compat code into common
authorDavid Mulder <dmulder@suse.com>
Fri, 11 Sep 2020 20:29:46 +0000 (14:29 -0600)
committerDavid Mulder <dmulder@samba.org>
Fri, 2 Oct 2020 14:49:36 +0000 (14:49 +0000)
The remaining compat code (get_string, get_bytes,
cmp) are useful helper routines which we should
simply merge into common (especially since there
is some duplication here).

Signed-off-by: David Mulder <dmulder@suse.com>
Reviewed-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
Autobuild-User(master): David Mulder <dmulder@samba.org>
Autobuild-Date(master): Fri Oct  2 14:49:36 UTC 2020 on sn-devel-184

49 files changed:
python/samba/common.py
python/samba/compat.py [deleted file]
python/samba/emulate/traffic.py
python/samba/gp_parse/__init__.py
python/samba/gp_sec_ext.py
python/samba/gpclass.py
python/samba/join.py
python/samba/kcc/__init__.py
python/samba/ms_forest_updates_markdown.py
python/samba/netcmd/computer.py
python/samba/netcmd/contact.py
python/samba/netcmd/domain.py
python/samba/netcmd/drs.py
python/samba/netcmd/group.py
python/samba/netcmd/user.py
python/samba/provision/sambadns.py
python/samba/samba3/__init__.py
python/samba/samdb.py
python/samba/schema.py
python/samba/tests/auth_log_netlogon_bad_creds.py
python/samba/tests/auth_log_winbind.py
python/samba/tests/blackbox/netads_json.py
python/samba/tests/blackbox/samba_dnsupdate.py
python/samba/tests/dcerpc/misc.py
python/samba/tests/gpo.py
python/samba/tests/krb5/kcrypto.py
python/samba/tests/ntlm_auth.py
python/samba/tests/prefork_restart.py
python/samba/tests/py_credentials.py
python/samba/tests/samba_tool/help.py
python/samba/tests/samba_tool/user.py
python/samba/upgradehelpers.py
selftest/filter-subunit
source3/script/tests/test_wbinfo_sids2xids_int.py
source4/dsdb/tests/python/acl.py
source4/dsdb/tests/python/deletetest.py
source4/dsdb/tests/python/ldap.py
source4/dsdb/tests/python/sam.py
source4/dsdb/tests/python/sort.py
source4/dsdb/tests/python/tombstone_reanimation.py
source4/dsdb/tests/python/vlv.py
source4/scripting/bin/samba_dnsupdate
source4/scripting/bin/samba_spnupdate
source4/scripting/bin/samba_upgradeprovision
source4/torture/drs/python/drs_base.py
source4/torture/drs/python/getnc_exop.py
source4/torture/drs/python/replica_sync_rodc.py
source4/torture/drs/python/samba_tool_drs_no_dns.py
source4/torture/drs/python/samba_tool_drs_showrepl.py

index a8faa90065da53c0f4ebed795139f10ab0fbd069..d5945307c3af174d9633d0ef01dc87e652b975ce 100644 (file)
@@ -1,6 +1,7 @@
 # Samba common functions
 #
 # Copyright (C) Matthieu Patou <mat@matws.net>
+# Copyright (C) Lumir Balhar <lbalhar@redhat.com> 2017
 #
 # This program is free software; you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 #
 
-from samba.compat import PY3
 
+def cmp(x, y):
+    """
+    Replacement for built-in function cmp that was removed in Python 3
 
-if PY3:
-    # cmp() exists only in Python 2
-    def cmp(a, b):
-        return (a > b) - (a < b)
+    Compare the two objects x and y and return an integer according to
+    the outcome. The return value is negative if x < y, zero if x == y
+    and strictly positive if x > y.
+    """
 
-    raw_input = input
+    return (x > y) - (x < y)
 
 
 def confirm(msg, forced=False, allow_all=False):
@@ -53,7 +56,7 @@ def confirm(msg, forced=False, allow_all=False):
         prompt = '[y/N/all/none]'
 
     while True:
-        v = raw_input(msg + ' %s ' % prompt)
+        v = input(msg + ' %s ' % prompt)
         v = v.upper()
         if v in mapping:
             return mapping[v]
@@ -67,3 +70,38 @@ def normalise_int32(ivalue):
     return str(ivalue)
 
 
+# Sometimes in PY3 we have variables whose content can be 'bytes' or
+# 'str' and we can't be sure which. Generally this is because the
+# code variable can be initialised (or reassigned) a value from different
+# api(s) or functions depending on complex conditions or logic. Or another
+# common case is in PY2 the variable is 'type <str>' and in PY3 it is
+# 'class <str>' and the function to use e.g. b64encode requires 'bytes'
+# in PY3. In such cases it would be nice to avoid excessive testing in
+# the client code. Calling such a helper function should be avoided
+# if possible but sometimes this just isn't possible.
+# If a 'str' object is passed in it is encoded using 'utf8' or if 'bytes'
+# is passed in it is returned unchanged.
+# Using this function is PY2/PY3 code should ensure in most cases
+# the PY2 code runs unchanged in PY2 whereas the code in PY3 possibly
+# encodes the variable (see PY2 implementation of this function below)
+def get_bytes(bytesorstring):
+    tmp = bytesorstring
+    if isinstance(bytesorstring, str):
+        tmp = bytesorstring.encode('utf8')
+    elif not isinstance(bytesorstring, bytes):
+        raise ValueError('Expected byte or string for %s:%s' % (type(bytesorstring), bytesorstring))
+    return tmp
+
+# helper function to get a string from a variable that maybe 'str' or
+# 'bytes' if 'bytes' then it is decoded using 'utf8'. If 'str' is passed
+# it is returned unchanged
+# Using this function is PY2/PY3 code should ensure in most cases
+# the PY2 code runs unchanged in PY2 whereas the code in PY3 possibly
+# decodes the variable (see PY2 implementation of this function below)
+def get_string(bytesorstring):
+    tmp = bytesorstring
+    if isinstance(bytesorstring, bytes):
+        tmp = bytesorstring.decode('utf8')
+    elif not isinstance(bytesorstring, str):
+        raise ValueError('Expected byte of string for %s:%s' % (type(bytesorstring), bytesorstring))
+    return tmp
diff --git a/python/samba/compat.py b/python/samba/compat.py
deleted file mode 100644 (file)
index a2b6f3c..0000000
+++ /dev/null
@@ -1,76 +0,0 @@
-# module which helps with porting to Python 3
-#
-# Copyright (C) Lumir Balhar <lbalhar@redhat.com> 2017
-#
-# This program is free software; you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation; either version 3 of the License, or
-# (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program.  If not, see <http://www.gnu.org/licenses/>.
-
-"""module which helps with porting to Python 3"""
-
-import sys
-
-PY3 = sys.version_info[0] == 3
-
-if PY3:
-    # Sometimes in PY3 we have variables whose content can be 'bytes' or
-    # 'str' and we can't be sure which. Generally this is because the
-    # code variable can be initialised (or reassigned) a value from different
-    # api(s) or functions depending on complex conditions or logic. Or another
-    # common case is in PY2 the variable is 'type <str>' and in PY3 it is
-    # 'class <str>' and the function to use e.g. b64encode requires 'bytes'
-    # in PY3. In such cases it would be nice to avoid excessive testing in
-    # the client code. Calling such a helper function should be avoided
-    # if possible but sometimes this just isn't possible.
-    # If a 'str' object is passed in it is encoded using 'utf8' or if 'bytes'
-    # is passed in it is returned unchanged.
-    # Using this function is PY2/PY3 code should ensure in most cases
-    # the PY2 code runs unchanged in PY2 whereas the code in PY3 possibly
-    # encodes the variable (see PY2 implementation of this function below)
-    def get_bytes(bytesorstring):
-        tmp = bytesorstring
-        if isinstance(bytesorstring, str):
-            tmp = bytesorstring.encode('utf8')
-        elif not isinstance(bytesorstring, bytes):
-            raise ValueError('Expected byte or string for %s:%s' % (type(bytesorstring), bytesorstring))
-        return tmp
-
-    # helper function to get a string from a variable that maybe 'str' or
-    # 'bytes' if 'bytes' then it is decoded using 'utf8'. If 'str' is passed
-    # it is returned unchanged
-    # Using this function is PY2/PY3 code should ensure in most cases
-    # the PY2 code runs unchanged in PY2 whereas the code in PY3 possibly
-    # decodes the variable (see PY2 implementation of this function below)
-    def get_string(bytesorstring):
-        tmp = bytesorstring
-        if isinstance(bytesorstring, bytes):
-            tmp = bytesorstring.decode('utf8')
-        elif not isinstance(bytesorstring, str):
-            raise ValueError('Expected byte of string for %s:%s' % (type(bytesorstring), bytesorstring))
-        return tmp
-
-    def cmp_fn(x, y):
-        """
-        Replacement for built-in function cmp that was removed in Python 3
-
-        Compare the two objects x and y and return an integer according to
-        the outcome. The return value is negative if x < y, zero if x == y
-        and strictly positive if x > y.
-        """
-
-        return (x > y) - (x < y)
-    # compat functions
-    from functools import cmp_to_key as cmp_to_key_fn
-
-
-else:
-    raise NotImplementedError("Samba versions >= 4.11 do not support Python 2.x")
index c428b4e369eb48f9d256650ea10f890de22a4835..9b6bdb6af57c003361f887cbdda49334e57da173 100644 (file)
@@ -53,7 +53,7 @@ from samba.dsdb import (
 from samba.dcerpc.misc import SEC_CHAN_BDC
 from samba import gensec
 from samba import sd_utils
-from samba.compat import get_string
+from samba.common import get_string
 from samba.logger import get_samba_logger
 import bisect
 
index 8ddd52d36571adce0e1396fa1a446e3fe33ce7fa..bc6058638f18682512555c2c8a74cdd91e9d29aa 100644 (file)
@@ -21,7 +21,7 @@ from xml.dom import minidom
 from io import BytesIO
 from xml.etree.ElementTree import ElementTree, fromstring, tostring
 from hashlib import md5
-from samba.compat import get_bytes
+from samba.common import get_bytes
 
 
 ENTITY_USER_ID = 0
index 070bde9fd60d911725017f0bfc344a2c4298e25c..136ba220de766e555ad42792967a4381e065198f 100644 (file)
@@ -18,7 +18,7 @@
 import os.path
 from samba.gpclass import gp_inf_ext
 from samba.auth import system_session
-from samba.compat import get_string
+from samba.common import get_string
 try:
     from ldb import LdbError
     from samba.samdb import SamDB
index 8e9bfb9f0e33bbb7bac1f1e499e4d19edd46280d..ac73671eb5883b356e209e580cb24786fe06e732 100644 (file)
@@ -23,7 +23,7 @@ sys.path.insert(0, "bin/python")
 from samba import NTSTATUSError
 from configparser import ConfigParser
 from io import StringIO
-from samba.compat import get_bytes
+from samba.common import get_bytes
 from abc import ABCMeta, abstractmethod
 import xml.etree.ElementTree as etree
 import re
index dca9ff634d5f24413ef5abfb1db8da79418353c2..59de000a4011edb35029efe51ef5290496dfb8e7 100644 (file)
@@ -49,7 +49,7 @@ import re
 import os
 import tempfile
 from collections import OrderedDict
-from samba.compat import get_string
+from samba.common import get_string
 from samba.netcmd import CommandError
 
 
index 734c7641883b2d30a2b6c4871fbfad3a7d59792a..73cdc9f1ef0570f926364e0b5de13d7f748a363b 100644 (file)
@@ -44,7 +44,7 @@ from samba.kcc.graph import Vertex
 
 from samba.kcc.debug import DEBUG, DEBUG_FN, logger
 from samba.kcc import debug
-from samba.compat import cmp_fn
+from samba.common import cmp
 
 
 def sort_dsa_by_gc_and_guid(dsa1, dsa2):
@@ -61,7 +61,7 @@ def sort_dsa_by_gc_and_guid(dsa1, dsa2):
         return -1
     if not dsa1.is_gc() and dsa2.is_gc():
         return +1
-    return cmp_fn(ndr_pack(dsa1.dsa_guid), ndr_pack(dsa2.dsa_guid))
+    return cmp(ndr_pack(dsa1.dsa_guid), ndr_pack(dsa2.dsa_guid))
 
 
 def is_smtp_replication_available():
index 62e9ad9b3546e93f7a57ca76941196bcca4cecd5..e219211d027891771e2ebd086db84e4c6c1688ac 100644 (file)
@@ -27,7 +27,7 @@ import re
 import os
 import markdown
 import xml.etree.ElementTree as ET
-from samba.compat import get_string
+from samba.common import get_string
 
 
 # Display specifier updates or otherwise (ignored in forest_update.py)
index 86c7b824d825b8308b7bd3fdf3b8155a96c677b6..9d7a220a0052162273d4abe597ec1a760d28a6a9 100644 (file)
@@ -34,7 +34,7 @@ from samba.ndr import ndr_unpack, ndr_pack, ndr_print
 from samba.remove_dc import remove_dns_references
 from samba.auth import system_session
 from samba.samdb import SamDB
-from samba.compat import get_bytes
+from samba.common import get_bytes
 from subprocess import check_call, CalledProcessError
 from . import common
 
index d3eeb23be64fd30a63e564a00c1a8b927c4ca6b7..064a3ce6691a4a87b6794d61da7b4d55312e58f7 100644 (file)
@@ -36,7 +36,7 @@ from samba.netcmd import (
     SuperCommand,
     Option,
 )
-from samba.compat import get_bytes
+from samba.common import get_bytes
 from . import common
 
 
index 238f3c306c1162ea30b2da67eef1e72c366878bc..000688f4e7a76ea69ede0eb72aad693dd0d7784e 100644 (file)
@@ -101,7 +101,7 @@ from samba.provision.common import (
 from samba.netcmd.pso import cmd_domain_passwordsettings_pso
 from samba.netcmd.domain_backup import cmd_domain_backup
 
-from samba.compat import get_string
+from samba.common import get_string
 
 string_version_to_constant = {
     "2008_R2": DS_DOMAIN_FUNCTION_2008_R2,
index cebcca5f48919f9d06aaabab43c2bec1edbb799f..023b09d0506a4754a9203508978f3607b17a0266 100644 (file)
@@ -46,7 +46,7 @@ from samba.uptodateness import (
     get_utdv_summary,
     get_kcc_and_dsas,
 )
-from samba.compat import get_string
+from samba.common import get_string
 from samba.samdb import get_default_backend_store
 
 def drsuapi_connect(ctx):
index 2942d553f2db29d0304e22d68db18c39a652db14..b5c86d33019c03c816ef1a17f8b2808177c25964 100644 (file)
@@ -36,7 +36,7 @@ from samba.dsdb import (
 )
 from collections import defaultdict
 from subprocess import check_call, CalledProcessError
-from samba.compat import get_bytes
+from samba.common import get_bytes
 import os
 import tempfile
 from . import common
index c49dccd704f78b85571d30932f8b0d237faf0917..f9762e761eabaabca3a90718ea0e7f0a3cb37539 100644 (file)
@@ -53,8 +53,8 @@ from samba.netcmd import (
     SuperCommand,
     Option,
 )
-from samba.compat import get_bytes
-from samba.compat import get_string
+from samba.common import get_bytes
+from samba.common import get_string
 from . import common
 
 # python[3]-gpgme is abandoned since ubuntu 1804 and debian 9
index 4aa132abfa6d8d6724f786250316f485f3c469d3..8a5d8a93442ce83950896f32b45f77ae9b2f18dd 100644 (file)
@@ -60,7 +60,7 @@ from samba.provision.common import (
 )
 
 from samba.samdb import get_default_backend_store
-from samba.compat import get_string
+from samba.common import get_string
 
 def get_domainguid(samdb, domaindn):
     res = samdb.search(base=domaindn, scope=ldb.SCOPE_BASE, attrs=["objectGUID"])
index b092f4509532c8e67803504f0565e8af26da12ac..f15bb291394896b877d846abc4d09cfeb8d6dc38 100644 (file)
@@ -28,7 +28,7 @@ import tdb
 
 from samba.samba3 import passdb
 from samba.samba3 import param as s3param
-from samba.compat import get_bytes
+from samba.common import get_bytes
 
 def fetch_uint32(db, key):
     try:
index 1da59dcdaab97f2febe66748e0aff9a5e5d924bc..0ec91ed3970281d97cdd7e3076ce300991f976d9 100644 (file)
@@ -32,7 +32,7 @@ from samba import dsdb, dsdb_dns
 from samba.ndr import ndr_unpack, ndr_pack
 from samba.dcerpc import drsblobs, misc
 from samba.common import normalise_int32
-from samba.compat import get_bytes, cmp
+from samba.common import get_bytes, cmp
 from samba.dcerpc import security
 import binascii
 
index caea7e358aebd00a3b80001e34acd02ab11a4a3b..54fc9fc31259a0a870e062f0ac2d6c639aa2d4ea 100644 (file)
@@ -28,7 +28,7 @@ from samba.dcerpc import security
 from samba.ms_schema import read_ms_schema
 from samba.ndr import ndr_pack
 from samba.samdb import SamDB
-from samba.compat import get_string
+from samba.common import get_string
 from samba import dsdb
 from ldb import SCOPE_SUBTREE, SCOPE_ONELEVEL
 
index a89c0312d1a90f3b5dc9f71c3312441a4504955c..a74ea5c706d9c550333dbe473cac4ff1182f4b72 100644 (file)
@@ -37,7 +37,7 @@ from samba.tests import delete_force
 from samba.dsdb import UF_WORKSTATION_TRUST_ACCOUNT, UF_PASSWD_NOTREQD
 from samba.dcerpc.misc import SEC_CHAN_WKSTA
 from samba.dcerpc.netlogon import NETLOGON_NEG_STRONG_KEYS
-from samba.compat import get_string
+from samba.common import get_string
 from samba.dcerpc.windows_event_ids import (
     EVT_ID_UNSUCCESSFUL_LOGON,
     EVT_LOGON_NETWORK
index dcb12fdb4c0d57a5d7a756af895aff004d201228..617fec42dbef941f7afb58d5dc89eeb14ed94a23 100644 (file)
@@ -25,7 +25,7 @@ import time
 
 from samba.auth import system_session
 from samba.credentials import Credentials
-from samba.compat import get_string, get_bytes
+from samba.common import get_string, get_bytes
 from samba.dcerpc.messaging import AUTH_EVENT_NAME, MSG_AUTH_LOG
 from samba.dsdb import UF_NORMAL_ACCOUNT
 from samba.messaging import Messaging
index 1c254468d36748b9759457bc00a1419c2916d4cf..bcae96259c95af7b124db5667b0438b074604aa7 100644 (file)
@@ -19,7 +19,7 @@ import json
 import re
 
 import samba.tests
-from samba.compat import get_string
+from samba.common import get_string
 
 COMMAND         = "bin/net ads"
 # extract keys from non-json version
index 4360f741217b67734e19ac7dd9244a2fc14e2729..ae65426e57db495c2673b049db2874e27ef5c779 100644 (file)
@@ -18,7 +18,7 @@
 
 import samba.tests
 from io import StringIO
-from samba.compat import get_string
+from samba.common import get_string
 from samba.netcmd.main import cmd_sambatool
 from samba.credentials import Credentials
 from samba.auth import system_session
index 009d8d02768ce79d9052fa226f7ff1fb9458a205..6b58e9451c8a675ea515cd85a5cfc37e67e70080 100644 (file)
 
 from samba.dcerpc import misc
 import samba.tests
-from samba.compat import PY3
+from samba.common import cmp
 
 text1 = "76f53846-a7c2-476a-ae2c-20e2b80d7b34"
 text2 = "344edffa-330a-4b39-b96e-2c34da52e8b1"
 text3 = "00112233-4455-6677-8899-aabbccddeeff"
 
 
-if PY3:
-    # cmp() exists only in Python 2
-    def cmp(a, b):
-        return (a > b) - (a < b)
-
-
 class GUIDTests(samba.tests.TestCase):
 
     def test_str(self):
index c8440929b11435c91c00277850c4595b02889d5b..115b71ac61d57e0346abb69a3480fbd0645cc78a 100644 (file)
@@ -32,7 +32,7 @@ from samba.gp_smb_conf_ext import gp_smb_conf_ext
 import logging
 from samba.credentials import Credentials
 from samba.gp_msgs_ext import gp_msgs_ext
-from samba.compat import get_bytes
+from samba.common import get_bytes
 from samba.dcerpc import preg
 from samba.ndr import ndr_pack
 import codecs
index 2572fa5bab3a2d24f55398b370c30db74134190c..64bdbecd8b2d9c5d34bed151338592324d69b11a 100755 (executable)
@@ -62,7 +62,7 @@ from cryptography.hazmat.primitives.kdf.pbkdf2 import PBKDF2HMAC
 from samba.tests import TestCase
 from samba.credentials import Credentials
 from samba import generate_random_bytes as get_random_bytes
-from samba.compat import get_string, get_bytes
+from samba.common import get_string, get_bytes
 
 class Enctype(object):
     DES_CRC = 1
index f6ae708ad246603957405696ff6089db70ba1735..b909db4e8a18ec93d0a0531c6804ca3b2544cdb9 100644 (file)
@@ -19,7 +19,7 @@
 import os
 from subprocess import Popen, PIPE
 from samba.tests.ntlm_auth_base import NTLMAuthTestCase
-from samba.compat import get_string
+from samba.common import get_string
 
 class NTLMAuthHelpersTests(NTLMAuthTestCase):
 
index 8557ae0d8d703364987c4fa54b8835aa173d4e84..2acbcc9befca5e023b9ff49b92449bc6802f1d32 100644 (file)
@@ -33,7 +33,7 @@ from samba.dcerpc import echo, netlogon
 from samba.messaging import Messaging
 from samba.samdb import SamDB
 from samba.credentials import Credentials, DONT_USE_KERBEROS
-from samba.compat import get_string
+from samba.common import get_string
 from samba.dsdb import (
     UF_WORKSTATION_TRUST_ACCOUNT,
     UF_PASSWD_NOTREQD)
index b16c726a023a890fdcf51710fa40cc85fcbf573b..ecb8271b5953dcbee5637a761a1c57ff89589118 100644 (file)
@@ -39,7 +39,7 @@ from samba.dsdb import (
 from samba.ndr import ndr_pack
 from samba.samdb import SamDB
 from samba import NTSTATUSError, ntstatus
-from samba.compat import get_string
+from samba.common import get_string
 
 import ctypes
 
index 669895041ea596dfb5bcea7d812c39654ad89a29..fa7836d8432bfbf758895e38c9012157004b8abd 100644 (file)
@@ -21,7 +21,7 @@ import re
 from samba.tests.samba_tool.base import SambaToolCmdTest
 from samba.tests import BlackboxProcessError
 from samba.tests import check_help_consistency
-from samba.compat import get_string
+from samba.common import get_string
 
 
 class HelpTestCase(SambaToolCmdTest):
index c710623339c1eb9d622a8d11eb80a5cb0bbb480d..22f76333ae27330c743dd545906d5cde381543c8 100644 (file)
@@ -27,8 +27,8 @@ from samba import (
         )
 from samba.ndr import ndr_unpack
 from samba.dcerpc import drsblobs
-from samba.compat import get_bytes
-from samba.compat import get_string
+from samba.common import get_bytes
+from samba.common import get_string
 from samba.tests import env_loadparm
 
 
index bc16590df28a3bfdf236eb76b7c9517dd3c4cd48..69f6e3675e8e1f67586db1696633a08e06bd2eac 100644 (file)
@@ -28,7 +28,7 @@ import re
 import shutil
 import samba
 
-from samba.compat import cmp_fn
+from samba.common import cmp
 from samba import Ldb, version, ntacls
 from ldb import SCOPE_SUBTREE, SCOPE_ONELEVEL, SCOPE_BASE
 import ldb
@@ -284,7 +284,7 @@ def dn_sort(x, y):
     len2 = len(tab2) - 1
     # Note: python range go up to upper limit but do not include it
     for i in range(0, minimum):
-        ret = cmp_fn(tab1[len1 - i], tab2[len2 - i])
+        ret = cmp(tab1[len1 - i], tab2[len2 - i])
         if ret != 0:
             return ret
         else:
index d67fbaceb51e0d4edb33aafcc4a568bf2ffafb2b..99e1c41e5ee97bc4d9178959d1a19c83144fdc24 100755 (executable)
@@ -102,12 +102,8 @@ else:
                                       flapping=flapping)
 
 try:
-    from samba.compat import PY3
     from io import TextIOWrapper as TextIOWrapper
-    if PY3:
-        forgiving_stdin = TextIOWrapper(sys.stdin.buffer, errors='ignore',  encoding='utf-8')
-    else:
-        forgiving_stdin = sys.stdin
+    forgiving_stdin = TextIOWrapper(sys.stdin.buffer, errors='ignore',  encoding='utf-8')
     ret = subunithelper.parse_results(msg_ops, statistics, forgiving_stdin)
 except subunithelper.ImmediateFail:
     sys.stdout.flush()
index cb8d8fe2af329b92749bd892c09713396a25a5bc..748141949ed2baf5a6d45b0a43da37d89b2ff921 100755 (executable)
@@ -4,7 +4,7 @@ from __future__ import print_function
 import sys
 import os
 import subprocess
-from samba.compat import get_string
+from samba.common import get_string
 
 
 if len(sys.argv) != 3:
index 6c46a6130dfc407ec42f86817c2127cf18a54ac7..33810ac6895ba7c1229e60001def8cdc2bc5bfaf 100755 (executable)
@@ -11,7 +11,7 @@ sys.path.insert(0, "bin/python")
 import samba
 
 from samba.tests.subunitrun import SubunitOptions, TestProgram
-from samba.compat import get_string
+from samba.common import get_string
 
 import samba.getopt as options
 from samba.join import DCJoinContext
index a2a19a126505dc28167e74b46815bf198980a416..612396002d64d11ba4842696f14c5a3c8e1a332b 100755 (executable)
@@ -20,7 +20,7 @@ from ldb import ERR_UNWILLING_TO_PERFORM, ERR_OPERATIONS_ERROR
 from samba.samdb import SamDB
 from samba.tests import delete_force
 from samba import dsdb
-from samba.compat import get_string
+from samba.common import get_string
 
 parser = optparse.OptionParser("deletetest.py [options] <host|file>")
 sambaopts = options.SambaOptions(parser)
index a90bf367b1bce6ab2807b701da686690ddd3b426..9c836c04267fce8296901187b218485e1a909a36 100755 (executable)
@@ -52,7 +52,7 @@ from samba.dsdb import (UF_NORMAL_ACCOUNT,
 from samba.ndr import ndr_pack, ndr_unpack
 from samba.dcerpc import security, lsa
 from samba.tests import delete_force
-from samba.compat import get_string
+from samba.common import get_string
 
 parser = optparse.OptionParser("ldap.py [options] <host>")
 sambaopts = options.SambaOptions(parser)
index d6ca63aedf6a060f3fb74b0da7331c6278a09482..41c348bce5f150d0bc324280fdc8867a5584f944 100755 (executable)
@@ -16,7 +16,7 @@ import samba.getopt as options
 
 from samba.credentials import Credentials, DONT_USE_KERBEROS
 from samba.auth import system_session
-from samba.compat import get_string
+from samba.common import get_string
 
 from ldb import SCOPE_BASE, LdbError
 from ldb import ERR_NO_SUCH_OBJECT, ERR_ATTRIBUTE_OR_VALUE_EXISTS
index 7b929eaefb66267293473ab63bf7cbd0401e48af..51d797af38d403c388ed26df2411685c413eeacf 100644 (file)
@@ -14,8 +14,8 @@ import re
 sys.path.insert(0, "bin/python")
 import samba
 from samba.tests.subunitrun import SubunitOptions, TestProgram
-from samba.compat import cmp_fn
-from samba.compat import cmp_to_key_fn
+from samba.common import cmp
+from functools import cmp_to_key
 import samba.getopt as options
 
 from samba.auth import system_session
@@ -285,10 +285,10 @@ class BaseSortTests(samba.tests.TestCase):
             return locale.strcoll(a[0], b[0])
 
         def cmp_binary(a, b):
-            return cmp_fn(a[0], b[0])
+            return cmp(a[0], b[0])
 
         def cmp_numeric(a, b):
-            return cmp_fn(int(a[0]), int(b[0]))
+            return cmp(int(a[0]), int(b[0]))
 
         # For testing simplicity, the attributes in here need to be
         # unique for each user. Otherwise there are multiple possible
@@ -303,7 +303,7 @@ class BaseSortTests(samba.tests.TestCase):
         for sort_attr, result_attr in attr_pairs:
             forward = sorted(((norm(x[sort_attr]), norm(x[result_attr]))
                              for x in self.users),
-                             key=cmp_to_key_fn(sort_functions[sort_attr]))
+                             key=cmp_to_key(sort_functions[sort_attr]))
             reverse = list(reversed(forward))
 
             for rev in (0, 1):
index 3c15c8e176f6083df6722d85a6ef0c8e73a25d5c..ad2ef80c09e6cf66c369cd4c64f4f3f926d90e9b 100755 (executable)
@@ -31,7 +31,7 @@ from samba.dcerpc import security
 from samba.dcerpc import drsblobs
 from samba.dcerpc.drsuapi import *
 from samba.tests.password_test import PasswordCommon
-from samba.compat import get_string
+from samba.common import get_string
 
 import samba.tests
 from ldb import (SCOPE_BASE, FLAG_MOD_ADD, FLAG_MOD_DELETE, FLAG_MOD_REPLACE, Dn, Message,
index 86ac2b72240c3b07b4f82c08e0de7bf2beda34ac..c7578c6f04bfad936131e31267a954ac39ed1ffe 100644 (file)
@@ -18,8 +18,8 @@ import samba.getopt as options
 from samba.auth import system_session
 import ldb
 from samba.samdb import SamDB
-from samba.compat import get_bytes
-from samba.compat import get_string
+from samba.common import get_bytes
+from samba.common import get_string
 
 import time
 
index 50381d8882329331cb9c35c0b456dbd43086311d..fcd4cc5b7da326e10f2e5c323b942d4e0fc3860d 100755 (executable)
@@ -49,7 +49,7 @@ from samba.dcerpc import netlogon, winbind
 from samba.netcmd.dns import cmd_dns
 from samba import gensec
 from samba.kcc import kcc_utils
-from samba.compat import get_string
+from samba.common import get_string
 import ldb
 
 import dns.resolver
index 9d3a7fab4d94ec2df77330934f4e2dd00b2e2123..84ff771eab2a5dfa332ac889906fc03eb12f46d6 100755 (executable)
@@ -41,7 +41,7 @@ from samba import getopt as options
 from samba.auth import system_session
 from samba.samdb import SamDB
 from samba.credentials import Credentials, DONT_USE_KERBEROS
-from samba.compat import get_string
+from samba.common import get_string
 
 parser = optparse.OptionParser("samba_spnupdate")
 sambaopts = options.SambaOptions(parser)
index 6ac4da6987a0f0de825187c64ad50b35430c8980..376c4c06318911289d01a906fd172e74b74bfb31 100755 (executable)
@@ -70,7 +70,7 @@ from samba.upgradehelpers import (dn_sort, get_paths, newprovision,
                                  increment_calculated_keyversion_number,
                                  print_provision_ranges)
 from samba.xattr import copytree_with_xattrs
-from samba.compat import cmp_to_key_fn
+from functools import cmp_to_key
 
 # make sure the script dies immediately when hitting control-C,
 # rather than raising KeyboardInterrupt. As we do all database
@@ -1130,8 +1130,8 @@ def update_partition(ref_samdb, samdb, basedn, names, schema, provisionUSNs, pre
 
     # Sort the missing object in order to have object of the lowest level
     # first (which can be containers for higher level objects)
-    listMissing.sort(key=cmp_to_key_fn(dn_sort))
-    listPresent.sort(key=cmp_to_key_fn(dn_sort))
+    listMissing.sort(key=cmp_to_key(dn_sort))
+    listPresent.sort(key=cmp_to_key(dn_sort))
 
     # The following lines is to load the up to
     # date schema into our current LDB
index 33fb1b3a89a6c5dc0f3d75de0630a1e79d49f8e5..0046ae235f1a6ebc03eb32946cf42c9d7b50d562 100644 (file)
@@ -39,8 +39,8 @@ from ldb import (
     Message,
     FLAG_MOD_REPLACE,
 )
-from samba.compat import cmp_fn
-from samba.compat import get_string
+from samba.common import cmp
+from samba.common import get_string
 
 
 class DrsBaseTestCase(SambaToolCmdTest):
@@ -529,7 +529,7 @@ class AbstractLink:
                 print("AbstractLink.__internal_cmp__(%r, %r) => wrong type" % (self, other))
             return NotImplemented
 
-        c = cmp_fn(self.selfGUID_blob, other.selfGUID_blob)
+        c = cmp(self.selfGUID_blob, other.selfGUID_blob)
         if c != 0:
             if verbose:
                 print("AbstractLink.__internal_cmp__(%r, %r) => %d different identifier" % (self, other, c))
@@ -550,7 +550,7 @@ class AbstractLink:
                 print("AbstractLink.__internal_cmp__(%r, %r) => %d different FLAG_ACTIVE" % (self, other, c))
             return c
 
-        c = cmp_fn(self.targetGUID_blob, other.targetGUID_blob)
+        c = cmp(self.targetGUID_blob, other.targetGUID_blob)
         if c != 0:
             if verbose:
                 print("AbstractLink.__internal_cmp__(%r, %r) => %d different target" % (self, other, c))
index 87571ca252ba320e142106e2df0711d8a3473c6b..446c7821d54bc92a69c714243dae7752a01c19e5 100644 (file)
@@ -42,8 +42,8 @@ from ldb import SCOPE_BASE
 from samba.dcerpc import drsuapi, misc, drsblobs
 from samba.drs_utils import drs_DsBind
 from samba.ndr import ndr_unpack, ndr_pack
-from samba.compat import cmp_to_key_fn
-from samba.compat import cmp_fn
+from functools import cmp_to_key
+from samba.common import cmp
 
 
 def _linked_attribute_compare(la1, la2):
@@ -52,7 +52,7 @@ def _linked_attribute_compare(la1, la2):
     la2, la2_target = la2
 
     # Ascending host object GUID
-    c = cmp_fn(ndr_pack(la1.identifier.guid), ndr_pack(la2.identifier.guid))
+    c = cmp(ndr_pack(la1.identifier.guid), ndr_pack(la2.identifier.guid))
     if c != 0:
         return c
 
@@ -68,7 +68,7 @@ def _linked_attribute_compare(la1, la2):
         return 1 if la1_active else -1
 
     # Ascending target object GUID
-    return cmp_fn(ndr_pack(la1_target), ndr_pack(la2_target))
+    return cmp(ndr_pack(la1_target), ndr_pack(la2_target))
 
 
 class DrsReplicaSyncTestCase(drs_base.DrsBaseTestCase):
@@ -1057,7 +1057,7 @@ class DrsReplicaSyncSortTestCase(drs_base.DrsBaseTestCase):
                                          link.identifier.guid,
                                          target_guid) in expected_links)
 
-        no_inactive.sort(key=cmp_to_key_fn(_linked_attribute_compare))
+        no_inactive.sort(key=cmp_to_key(_linked_attribute_compare))
 
         # assert the two arrays are the same
         self.assertEqual(len(expected_links), ctr.linked_attributes_count)
@@ -1081,7 +1081,7 @@ class DrsReplicaSyncSortTestCase(drs_base.DrsBaseTestCase):
                                          link.identifier.guid,
                                          target_guid) in expected_links)
 
-        has_inactive.sort(key=cmp_to_key_fn(_linked_attribute_compare))
+        has_inactive.sort(key=cmp_to_key(_linked_attribute_compare))
 
         # assert the two arrays are the same
         self.assertEqual(len(expected_links), ctr.linked_attributes_count)
@@ -1129,7 +1129,7 @@ class DrsReplicaSyncSortTestCase(drs_base.DrsBaseTestCase):
                                          link.value.blob).guid
             no_inactive.append((link, target_guid))
 
-        no_inactive.sort(key=cmp_to_key_fn(_linked_attribute_compare))
+        no_inactive.sort(key=cmp_to_key(_linked_attribute_compare))
 
         # assert the two arrays are the same
         self.assertEqual([x[0] for x in no_inactive], ctr.linked_attributes)
index b904e17575cd1cc18dbd2cf54f2e59eb2a07c0c0..cbdcc12e5ae7f80ff693c64f052159f3f0743b1d 100644 (file)
@@ -32,7 +32,7 @@ import drs_base
 import samba.tests
 import time
 import ldb
-from samba.compat import get_string
+from samba.common import get_string
 
 from ldb import (
     SCOPE_BASE, LdbError, ERR_NO_SUCH_OBJECT)
index 326181a7fd7341e4cadb6bc20da98eba42dcf737..41ae51374ceb80a799d021a80410dc34e83d3618 100644 (file)
@@ -30,7 +30,7 @@ import ldb
 import drs_base
 
 from samba.tests import BlackboxProcessError
-from samba.compat import get_string
+from samba.common import get_string
 
 
 class SambaToolDrsNoDnsTests(drs_base.DrsBaseTestCase):
index f04ee122f0434fd54cccc1bdc47397bf731335ae..e77f15d2b5415714ace5a111104b66c9d18f4e6c 100644 (file)
@@ -26,7 +26,7 @@ import re
 import json
 import ldb
 import random
-from samba.compat import get_string
+from samba.common import get_string
 
 GUID_RE = r'[\da-f]{8}-[\da-f]{4}-[\da-f]{4}-[\da-f]{4}-[\da-f]{12}'
 HEX8_RE = r'0x[\da-f]{8}'