From ace5038031f3b7f7017da2ad0076b9f8fca59d10 Mon Sep 17 00:00:00 2001 From: Douglas Bagnall Date: Sat, 4 Jul 2020 14:05:16 +1200 Subject: [PATCH] python compat: remove binary_type Signed-off-by: Douglas Bagnall Reviewed-by: Noel Power --- python/samba/compat.py | 1 - python/samba/netcmd/domain.py | 3 +-- python/samba/provision/__init__.py | 3 +-- python/samba/samdb.py | 9 ++++----- python/samba/tests/dcerpc/raw_protocol.py | 5 ++--- python/samba/tests/dns_base.py | 7 +++---- selftest/subunithelper.py | 3 +-- 7 files changed, 12 insertions(+), 19 deletions(-) diff --git a/python/samba/compat.py b/python/samba/compat.py index c675702ca95..299b1c8a301 100644 --- a/python/samba/compat.py +++ b/python/samba/compat.py @@ -73,7 +73,6 @@ if PY3: # compat types text_type = str - binary_type = bytes # alias def ConfigParser(defaults=None, dict_type=dict, allow_no_value=False): diff --git a/python/samba/netcmd/domain.py b/python/samba/netcmd/domain.py index 8561188511e..238f3c306c1 100644 --- a/python/samba/netcmd/domain.py +++ b/python/samba/netcmd/domain.py @@ -101,7 +101,6 @@ 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 binary_type from samba.compat import get_string string_version_to_constant = { @@ -536,7 +535,7 @@ class cmd_domain_provision(Command): def _adminpass_issue(self, adminpass): """Returns error string for a bad administrator password, or None if acceptable""" - if isinstance(adminpass, binary_type): + if isinstance(adminpass, bytes): adminpass = adminpass.decode('utf8') if len(adminpass) < DEFAULT_MIN_PWD_LENGTH: return "Administrator password does not meet the default minimum" \ diff --git a/python/samba/provision/__init__.py b/python/samba/provision/__init__.py index 4ac89ef406f..0706f39c581 100644 --- a/python/samba/provision/__init__.py +++ b/python/samba/provision/__init__.py @@ -27,7 +27,6 @@ __docformat__ = "restructuredText" from urllib.parse import quote as urllib_quote -from samba.compat import binary_type from base64 import b64encode import errno import os @@ -2332,7 +2331,7 @@ def provision(logger, session_info, smbconf=None, adminpass = samba.generate_random_password(12, 32) adminpass_generated = True else: - if isinstance(adminpass, binary_type): + if isinstance(adminpass, bytes): adminpass = adminpass.decode('utf-8') adminpass_generated = False diff --git a/python/samba/samdb.py b/python/samba/samdb.py index d903babb406..002e07e645b 100644 --- a/python/samba/samdb.py +++ b/python/samba/samdb.py @@ -33,7 +33,6 @@ from samba.ndr import ndr_unpack, ndr_pack from samba.dcerpc import drsblobs, misc from samba.common import normalise_int32 from samba.compat import text_type -from samba.compat import binary_type from samba.compat import get_bytes from samba.dcerpc import security @@ -1098,7 +1097,7 @@ schemaUpdateNow: 1 return dn def set_minPwdAge(self, value): - if not isinstance(value, binary_type): + if not isinstance(value, bytes): value = str(value).encode('utf8') m = ldb.Message() m.dn = ldb.Dn(self, self.domain_dn()) @@ -1115,7 +1114,7 @@ schemaUpdateNow: 1 return int(res[0]["minPwdAge"][0]) def set_maxPwdAge(self, value): - if not isinstance(value, binary_type): + if not isinstance(value, bytes): value = str(value).encode('utf8') m = ldb.Message() m.dn = ldb.Dn(self, self.domain_dn()) @@ -1132,7 +1131,7 @@ schemaUpdateNow: 1 return int(res[0]["maxPwdAge"][0]) def set_minPwdLength(self, value): - if not isinstance(value, binary_type): + if not isinstance(value, bytes): value = str(value).encode('utf8') m = ldb.Message() m.dn = ldb.Dn(self, self.domain_dn()) @@ -1149,7 +1148,7 @@ schemaUpdateNow: 1 return int(res[0]["minPwdLength"][0]) def set_pwdProperties(self, value): - if not isinstance(value, binary_type): + if not isinstance(value, bytes): value = str(value).encode('utf8') m = ldb.Message() m.dn = ldb.Dn(self, self.domain_dn()) diff --git a/python/samba/tests/dcerpc/raw_protocol.py b/python/samba/tests/dcerpc/raw_protocol.py index f810cad3d2f..dc13d41c6a2 100755 --- a/python/samba/tests/dcerpc/raw_protocol.py +++ b/python/samba/tests/dcerpc/raw_protocol.py @@ -33,7 +33,6 @@ import samba.dcerpc.lsa import struct from samba import gensec from samba.tests.dcerpc.raw_testcase import RawDCERPCTest -from samba.compat import binary_type from samba.ntstatus import ( NT_STATUS_SUCCESS ) @@ -1930,12 +1929,12 @@ class TestDCERPC_BIND(RawDCERPCTest): epmap=True, return_ack=True) server = '\\\\' + self.target_hostname - if isinstance(server, binary_type): + if isinstance(server, bytes): server_utf16 = server.decode('utf-8').encode('utf-16-le') else: server_utf16 = server.encode('utf-16-le') computer = 'UNKNOWNCOMPUTER' - if isinstance(server, binary_type): + if isinstance(server, bytes): computer_utf16 = computer.decode('utf-8').encode('utf-16-le') else: computer_utf16 = computer.encode('utf-16-le') diff --git a/python/samba/tests/dns_base.py b/python/samba/tests/dns_base.py index c90e48d1fc0..a5c7c5eb982 100644 --- a/python/samba/tests/dns_base.py +++ b/python/samba/tests/dns_base.py @@ -27,7 +27,6 @@ import random import socket import uuid import time -from samba.compat import binary_type class DNSTest(TestCaseInTempDir): @@ -278,7 +277,7 @@ class DNSTKeyTest(DNSTest): self.assert_dns_rcode_equals(response, dns.DNS_RCODE_OK) tkey_record = response.answers[0].rdata - server_to_client = binary_type(bytearray(tkey_record.key_data)) + server_to_client = bytes(tkey_record.key_data) (finished, client_to_server) = self.g.update(server_to_client) self.assertTrue(finished) @@ -288,7 +287,7 @@ class DNSTKeyTest(DNSTest): self.assertEqual(response.additional[0].rr_type, dns.DNS_QTYPE_TSIG) tsig_record = response.additional[0].rdata - mac = binary_type(bytearray(tsig_record.mac)) + mac = bytes(tsig_record.mac) # Cut off tsig record from dns response packet for MAC verification # and reset additional record count. @@ -305,7 +304,7 @@ class DNSTKeyTest(DNSTest): response_packet_list[11] = chr(0) # convert modified list (of string char or int) to str/bytes - response_packet_wo_tsig = binary_type(bytearray(response_packet_list)) + response_packet_wo_tsig = bytes(response_packet_list) fake_tsig = dns.fake_tsig_rec() fake_tsig.name = self.key_name diff --git a/selftest/subunithelper.py b/selftest/subunithelper.py index 651d9b00289..baab146ca60 100644 --- a/selftest/subunithelper.py +++ b/selftest/subunithelper.py @@ -26,7 +26,6 @@ from samba import subunit from samba.subunit.run import TestProtocolClient from samba.subunit import iso8601 import unittest -from samba.compat import binary_type VALID_RESULTS = set(['success', 'successful', 'failure', 'fail', 'skip', @@ -93,7 +92,7 @@ def parse_results(msg_ops, statistics, fh): else: reason += l - if isinstance(reason, binary_type): + if isinstance(reason, bytes): remote_error = subunit.RemoteError(reason.decode("utf-8")) else: remote_error = subunit.RemoteError(reason)