mirror of
https://github.com/samba-team/samba.git
synced 2025-01-03 01:18:10 +03:00
python2 reduction: Merge remaining compat code into common
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
This commit is contained in:
parent
85d2ff2f00
commit
a3cd315321
@ -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
|
||||
@ -16,15 +17,17 @@
|
||||
# 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
|
||||
|
@ -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")
|
@ -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
|
||||
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
||||
|
||||
|
@ -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():
|
||||
|
@ -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)
|
||||
|
@ -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
|
||||
|
||||
|
@ -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
|
||||
|
||||
|
||||
|
@ -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,
|
||||
|
@ -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):
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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"])
|
||||
|
@ -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:
|
||||
|
@ -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
|
||||
|
||||
|
@ -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
|
||||
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -19,19 +19,13 @@
|
||||
|
||||
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):
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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):
|
||||
|
||||
|
@ -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)
|
||||
|
@ -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
|
||||
|
||||
|
@ -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):
|
||||
|
@ -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
|
||||
|
||||
|
||||
|
@ -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:
|
||||
|
@ -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()
|
||||
|
@ -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:
|
||||
|
@ -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
|
||||
|
@ -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)
|
||||
|
@ -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)
|
||||
|
@ -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
|
||||
|
@ -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):
|
||||
|
@ -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,
|
||||
|
@ -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
|
||||
|
||||
|
@ -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
|
||||
|
@ -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)
|
||||
|
@ -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
|
||||
|
@ -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))
|
||||
|
@ -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)
|
||||
|
@ -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)
|
||||
|
@ -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):
|
||||
|
@ -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}'
|
||||
|
Loading…
Reference in New Issue
Block a user