From c8ded4621d399e3561d6043bee4202ff42d50f1a Mon Sep 17 00:00:00 2001 From: Rob van der Linde Date: Thu, 14 Dec 2023 15:30:42 +1300 Subject: [PATCH] python: use python3 style super statements Signed-off-by: Rob van der Linde Reviewed-by: Douglas Bagnall Reviewed-by: Andrew Bartlett --- python/samba/dnsserver.py | 16 ++++++------ python/samba/drs_utils.py | 7 ++--- python/samba/gp_parse/gp_ini.py | 15 +++++------ python/samba/idmap.py | 10 +++---- python/samba/join.py | 24 ++++++++--------- python/samba/logger.py | 2 +- python/samba/netcmd/gpo.py | 3 +-- .../samba/netcmd/user/readpasswords/common.py | 2 +- python/samba/provision/__init__.py | 4 +-- python/samba/provision/sambadns.py | 26 +++++++++---------- python/samba/samdb.py | 11 ++++---- python/samba/subunit/run.py | 8 +++--- 12 files changed, 60 insertions(+), 68 deletions(-) diff --git a/python/samba/dnsserver.py b/python/samba/dnsserver.py index 965977acdeb..d907f8e1b8d 100644 --- a/python/samba/dnsserver.py +++ b/python/samba/dnsserver.py @@ -49,7 +49,7 @@ class DNSParseError(ValueError): class ARecord(dnsserver.DNS_RPC_RECORD): def __init__(self, ip_addr, serial=1, ttl=900, rank=dnsp.DNS_RANK_ZONE, node_flag=0): - super(ARecord, self).__init__() + super().__init__() self.wType = dnsp.DNS_TYPE_A self.dwFlags = rank | node_flag self.dwSerial = serial @@ -65,7 +65,7 @@ class AAAARecord(dnsserver.DNS_RPC_RECORD): def __init__(self, ip6_addr, serial=1, ttl=900, rank=dnsp.DNS_RANK_ZONE, node_flag=0): - super(AAAARecord, self).__init__() + super().__init__() self.wType = dnsp.DNS_TYPE_AAAA self.dwFlags = rank | node_flag self.dwSerial = serial @@ -81,7 +81,7 @@ class PTRRecord(dnsserver.DNS_RPC_RECORD): def __init__(self, ptr, serial=1, ttl=900, rank=dnsp.DNS_RANK_ZONE, node_flag=0): - super(PTRRecord, self).__init__() + super().__init__() self.wType = dnsp.DNS_TYPE_PTR self.dwFlags = rank | node_flag self.dwSerial = serial @@ -119,7 +119,7 @@ class NSRecord(dnsserver.DNS_RPC_RECORD): def __init__(self, dns_server, serial=1, ttl=900, rank=dnsp.DNS_RANK_ZONE, node_flag=0): - super(NSRecord, self).__init__() + super().__init__() self.wType = dnsp.DNS_TYPE_NS self.dwFlags = rank | node_flag self.dwSerial = serial @@ -138,7 +138,7 @@ class MXRecord(dnsserver.DNS_RPC_RECORD): def __init__(self, mail_server, preference, serial=1, ttl=900, rank=dnsp.DNS_RANK_ZONE, node_flag=0): - super(MXRecord, self).__init__() + super().__init__() self.wType = dnsp.DNS_TYPE_MX self.dwFlags = rank | node_flag self.dwSerial = serial @@ -165,7 +165,7 @@ class SOARecord(dnsserver.DNS_RPC_RECORD): def __init__(self, mname, rname, serial=1, refresh=900, retry=600, expire=86400, minimum=3600, ttl=3600, rank=dnsp.DNS_RANK_ZONE, node_flag=dnsp.DNS_RPC_FLAG_AUTH_ZONE_ROOT): - super(SOARecord, self).__init__() + super().__init__() self.wType = dnsp.DNS_TYPE_SOA self.dwFlags = rank | node_flag self.dwSerial = serial @@ -202,7 +202,7 @@ class SRVRecord(dnsserver.DNS_RPC_RECORD): def __init__(self, target, port, priority=0, weight=100, serial=1, ttl=900, rank=dnsp.DNS_RANK_ZONE, node_flag=0): - super(SRVRecord, self).__init__() + super().__init__() self.wType = dnsp.DNS_TYPE_SRV self.dwFlags = rank | node_flag self.dwSerial = serial @@ -237,7 +237,7 @@ class TXTRecord(dnsserver.DNS_RPC_RECORD): def __init__(self, slist, serial=1, ttl=900, rank=dnsp.DNS_RANK_ZONE, node_flag=0): - super(TXTRecord, self).__init__() + super().__init__() self.wType = dnsp.DNS_TYPE_TXT self.dwFlags = rank | node_flag self.dwSerial = serial diff --git a/python/samba/drs_utils.py b/python/samba/drs_utils.py index f3209e63eb9..06e6928e308 100644 --- a/python/samba/drs_utils.py +++ b/python/samba/drs_utils.py @@ -405,8 +405,7 @@ class drs_ReplicateRenamer(drs_Replicate): def __init__(self, binding_string, lp, creds, samdb, invocation_id, old_base_dn, new_base_dn): - super(drs_ReplicateRenamer, self).__init__(binding_string, lp, creds, - samdb, invocation_id) + super().__init__(binding_string, lp, creds, samdb, invocation_id) self.old_base_dn = old_base_dn self.new_base_dn = new_base_dn @@ -454,6 +453,4 @@ class drs_ReplicateRenamer(drs_Replicate): self.rename_top_level_object(ctr.first_object.object) # then do the normal repl processing to apply this chunk to our DB - super(drs_ReplicateRenamer, self).process_chunk(level, ctr, schema, - req_level, req, - first_chunk) + super().process_chunk(level, ctr, schema, req_level, req, first_chunk) diff --git a/python/samba/gp_parse/gp_ini.py b/python/samba/gp_parse/gp_ini.py index 342a1ee1620..e9b7ad29de9 100644 --- a/python/samba/gp_parse/gp_ini.py +++ b/python/samba/gp_parse/gp_ini.py @@ -109,7 +109,7 @@ class GPTIniParser(GPIniParser): def parse(self, contents): try: - super(GPTIniParser, self).parse(contents) + super().parse(contents) except UnicodeDecodeError: # Required dict_type in Python 2.7 self.ini_conf = ConfigParser(dict_type=collections.OrderedDict, @@ -122,9 +122,8 @@ class GPTIniParser(GPIniParser): class GPScriptsIniParser(GPIniParser): def build_xml_parameter(self, section_xml, section, key_ini, val_ini): - parent_return = super(GPScriptsIniParser, - self).build_xml_parameter(section_xml, section, - key_ini, val_ini) + parent_return = super().build_xml_parameter(section_xml, section, + key_ini, val_ini) cmdline = re.match('\\d+CmdLine$', key_ini) if cmdline is not None: @@ -136,9 +135,8 @@ class GPScriptsIniParser(GPIniParser): class GPFDeploy1IniParser(GPIniParser): def build_xml_parameter(self, section_xml, section, key_ini, val_ini): - parent_return = super(GPFDeploy1IniParser, - self).build_xml_parameter(section_xml, section, - key_ini, val_ini) + parent_return = super().build_xml_parameter(section_xml, section, + key_ini, val_ini) # Add generalization metadata and parse out SID list if section.lower() == 'folder_redirection': # Process the header section @@ -182,8 +180,7 @@ class GPFDeploy1IniParser(GPIniParser): return (key, value) # Do the normal ini code for other sections - return super(GPFDeploy1IniParser, - self).load_xml_parameter(param_xml, section) + return super().load_xml_parameter(param_xml, section) def build_xml_section(self, root_xml, sec_ini): section = SubElement(root_xml, 'Section') diff --git a/python/samba/idmap.py b/python/samba/idmap.py index 8abaf98cadb..321ae8b7ee5 100644 --- a/python/samba/idmap.py +++ b/python/samba/idmap.py @@ -42,13 +42,13 @@ class IDmapDB(samba.Ldb): if url is None: url = lp.private_path("idmap.ldb") - super(IDmapDB, self).__init__(url=url, lp=lp, modules_dir=modules_dir, - session_info=session_info, credentials=credentials, flags=flags, - options=options) + super().__init__(url=url, lp=lp, modules_dir=modules_dir, + session_info=session_info, credentials=credentials, flags=flags, + options=options) def connect(self, url=None, flags=0, options=None): - super(IDmapDB, self).connect(url=self.lp.private_path(url), flags=flags, - options=options) + super().connect(url=self.lp.private_path(url), flags=flags, + options=options) def increment_xid(self): """Increment xidNumber, if not present it create and assign it to the lowerBound diff --git a/python/samba/join.py b/python/samba/join.py index 4d08cccb567..8b7e882a236 100644 --- a/python/samba/join.py +++ b/python/samba/join.py @@ -54,7 +54,7 @@ from samba import dsdb, functional_level class DCJoinException(Exception): def __init__(self, msg): - super(DCJoinException, self).__init__("Can't join, error: %s" % msg) + super().__init__("Can't join, error: %s" % msg) class DCJoinContext(object): @@ -1651,11 +1651,11 @@ class DCCloneContext(DCJoinContext): targetdir=None, domain=None, dns_backend=None, include_secrets=False, backend_store=None, backend_store_size=None): - super(DCCloneContext, ctx).__init__(logger, server, creds, lp, - targetdir=targetdir, domain=domain, - dns_backend=dns_backend, - backend_store=backend_store, - backend_store_size=backend_store_size) + super().__init__(logger, server, creds, lp, + targetdir=targetdir, domain=domain, + dns_backend=dns_backend, + backend_store=backend_store, + backend_store_size=backend_store_size) # As we don't want to create or delete these DNs, we set them to None ctx.server_dn = None @@ -1706,12 +1706,12 @@ class DCCloneAndRenameContext(DCCloneContext): def __init__(ctx, new_base_dn, new_domain_name, new_realm, logger=None, server=None, creds=None, lp=None, targetdir=None, domain=None, dns_backend=None, include_secrets=True, backend_store=None): - super(DCCloneAndRenameContext, ctx).__init__(logger, server, creds, lp, - targetdir=targetdir, - domain=domain, - dns_backend=dns_backend, - include_secrets=include_secrets, - backend_store=backend_store) + super().__init__(logger, server, creds, lp, + targetdir=targetdir, + domain=domain, + dns_backend=dns_backend, + include_secrets=include_secrets, + backend_store=backend_store) # store the new DN (etc) that we want the cloned DB to use ctx.new_base_dn = new_base_dn ctx.new_domain_name = new_domain_name diff --git a/python/samba/logger.py b/python/samba/logger.py index 7fb2199e031..a35ef2a358f 100644 --- a/python/samba/logger.py +++ b/python/samba/logger.py @@ -34,7 +34,7 @@ class ColoredFormatter(logging.Formatter): """Add color to log according to level""" def format(self, record): - log = super(ColoredFormatter, self).format(record) + log = super().format(record) color = LEVEL_COLORS.get(record.levelno, GREY) return color + log + C_NORMAL diff --git a/python/samba/netcmd/gpo.py b/python/samba/netcmd/gpo.py index 823e048f400..ba55b2ec7a7 100644 --- a/python/samba/netcmd/gpo.py +++ b/python/samba/netcmd/gpo.py @@ -1660,8 +1660,7 @@ class cmd_restore(cmd_create): dtd_header += '\n]>\n' - super(cmd_restore, self).run(displayname, H, tmpdir, sambaopts, - credopts, versionopts) + super().run(displayname, H, tmpdir, sambaopts, credopts, versionopts) try: if tmpdir is None: diff --git a/python/samba/netcmd/user/readpasswords/common.py b/python/samba/netcmd/user/readpasswords/common.py index f9406844a3d..02f7d36f5fc 100644 --- a/python/samba/netcmd/user/readpasswords/common.py +++ b/python/samba/netcmd/user/readpasswords/common.py @@ -178,7 +178,7 @@ if len(disabled_virtual_attributes) != 0: class GetPasswordCommand(Command): def __init__(self): - super(GetPasswordCommand, self).__init__() + super().__init__() self.lp = None def inject_virtual_attributes(self, samdb): diff --git a/python/samba/provision/__init__.py b/python/samba/provision/__init__.py index f731d642d7f..56ca7496407 100644 --- a/python/samba/provision/__init__.py +++ b/python/samba/provision/__init__.py @@ -2511,14 +2511,14 @@ class InvalidNetbiosName(Exception): """A specified name was not a valid NetBIOS name.""" def __init__(self, name): - super(InvalidNetbiosName, self).__init__( + super().__init__( "The name '%r' is not a valid NetBIOS name" % name) class MissingShareError(ProvisioningError): def __init__(self, name, smbconf): - super(MissingShareError, self).__init__( + super().__init__( "Existing smb.conf does not have a [%s] share, but you are " "configuring a DC. Please remove %s or add the share manually." % (name, smbconf)) diff --git a/python/samba/provision/sambadns.py b/python/samba/provision/sambadns.py index f77329e2818..01398bbc346 100644 --- a/python/samba/provision/sambadns.py +++ b/python/samba/provision/sambadns.py @@ -86,7 +86,7 @@ def get_dnsadmins_sid(samdb, domaindn): class ARecord(dnsp.DnssrvRpcRecord): def __init__(self, ip_addr, serial=1, ttl=900, rank=dnsp.DNS_RANK_ZONE): - super(ARecord, self).__init__() + super().__init__() self.wType = dnsp.DNS_TYPE_A self.rank = rank self.dwSerial = serial @@ -97,7 +97,7 @@ class ARecord(dnsp.DnssrvRpcRecord): class AAAARecord(dnsp.DnssrvRpcRecord): def __init__(self, ip6_addr, serial=1, ttl=900, rank=dnsp.DNS_RANK_ZONE): - super(AAAARecord, self).__init__() + super().__init__() self.wType = dnsp.DNS_TYPE_AAAA self.rank = rank self.dwSerial = serial @@ -119,7 +119,7 @@ class CNAMERecord(dnsp.DnssrvRpcRecord): class NSRecord(dnsp.DnssrvRpcRecord): def __init__(self, dns_server, serial=1, ttl=900, rank=dnsp.DNS_RANK_ZONE): - super(NSRecord, self).__init__() + super().__init__() self.wType = dnsp.DNS_TYPE_NS self.rank = rank self.dwSerial = serial @@ -131,7 +131,7 @@ class SOARecord(dnsp.DnssrvRpcRecord): def __init__(self, mname, rname, serial=1, refresh=900, retry=600, expire=86400, minimum=3600, ttl=3600, rank=dnsp.DNS_RANK_ZONE): - super(SOARecord, self).__init__() + super().__init__() self.wType = dnsp.DNS_TYPE_SOA self.rank = rank self.dwSerial = serial @@ -151,7 +151,7 @@ class SRVRecord(dnsp.DnssrvRpcRecord): def __init__(self, target, port, priority=0, weight=100, serial=1, ttl=900, rank=dnsp.DNS_RANK_ZONE): - super(SRVRecord, self).__init__() + super().__init__() self.wType = dnsp.DNS_TYPE_SRV self.rank = rank self.dwSerial = serial @@ -167,7 +167,7 @@ class SRVRecord(dnsp.DnssrvRpcRecord): class TXTRecord(dnsp.DnssrvRpcRecord): def __init__(self, slist, serial=1, ttl=900, rank=dnsp.DNS_RANK_ZONE): - super(TXTRecord, self).__init__() + super().__init__() self.wType = dnsp.DNS_TYPE_TXT self.rank = rank self.dwSerial = serial @@ -181,7 +181,7 @@ class TXTRecord(dnsp.DnssrvRpcRecord): class TypeProperty(dnsp.DnsProperty): def __init__(self, zone_type=dnsp.DNS_ZONE_TYPE_PRIMARY): - super(TypeProperty, self).__init__() + super().__init__() self.wDataLength = 1 self.version = 1 self.id = dnsp.DSPROPERTY_ZONE_TYPE @@ -191,7 +191,7 @@ class TypeProperty(dnsp.DnsProperty): class AllowUpdateProperty(dnsp.DnsProperty): def __init__(self, allow_update=dnsp.DNS_ZONE_UPDATE_SECURE): - super(AllowUpdateProperty, self).__init__() + super().__init__() self.wDataLength = 1 self.version = 1 self.id = dnsp.DSPROPERTY_ZONE_ALLOW_UPDATE @@ -201,7 +201,7 @@ class AllowUpdateProperty(dnsp.DnsProperty): class SecureTimeProperty(dnsp.DnsProperty): def __init__(self, secure_time=0): - super(SecureTimeProperty, self).__init__() + super().__init__() self.wDataLength = 1 self.version = 1 self.id = dnsp.DSPROPERTY_ZONE_SECURE_TIME @@ -211,7 +211,7 @@ class SecureTimeProperty(dnsp.DnsProperty): class NorefreshIntervalProperty(dnsp.DnsProperty): def __init__(self, norefresh_interval=0): - super(NorefreshIntervalProperty, self).__init__() + super().__init__() self.wDataLength = 1 self.version = 1 self.id = dnsp.DSPROPERTY_ZONE_NOREFRESH_INTERVAL @@ -221,7 +221,7 @@ class NorefreshIntervalProperty(dnsp.DnsProperty): class RefreshIntervalProperty(dnsp.DnsProperty): def __init__(self, refresh_interval=0): - super(RefreshIntervalProperty, self).__init__() + super().__init__() self.wDataLength = 1 self.version = 1 self.id = dnsp.DSPROPERTY_ZONE_REFRESH_INTERVAL @@ -231,7 +231,7 @@ class RefreshIntervalProperty(dnsp.DnsProperty): class AgingStateProperty(dnsp.DnsProperty): def __init__(self, aging_enabled=0): - super(AgingStateProperty, self).__init__() + super().__init__() self.wDataLength = 1 self.version = 1 self.id = dnsp.DSPROPERTY_ZONE_AGING_STATE @@ -241,7 +241,7 @@ class AgingStateProperty(dnsp.DnsProperty): class AgingEnabledTimeProperty(dnsp.DnsProperty): def __init__(self, next_cycle_hours=0): - super(AgingEnabledTimeProperty, self).__init__() + super().__init__() self.wDataLength = 1 self.version = 1 self.id = dnsp.DSPROPERTY_ZONE_AGING_ENABLED_TIME diff --git a/python/samba/samdb.py b/python/samba/samdb.py index f2d7d4077c2..9bbec435062 100644 --- a/python/samba/samdb.py +++ b/python/samba/samdb.py @@ -87,9 +87,9 @@ class SamDB(samba.Ldb): self.url = url - super(SamDB, self).__init__(url=url, lp=lp, modules_dir=modules_dir, - session_info=session_info, credentials=credentials, flags=flags, - options=options) + super().__init__(url=url, lp=lp, modules_dir=modules_dir, + session_info=session_info, credentials=credentials, flags=flags, + options=options) if global_schema: dsdb._dsdb_set_global_schema(self) @@ -103,8 +103,7 @@ class SamDB(samba.Ldb): url = self.lp.private_path(url) self.url = url - super(SamDB, self).connect(url=url, flags=flags, - options=options) + super().connect(url=url, flags=flags, options=options) def am_rodc(self): """return True if we are an RODC""" @@ -1357,7 +1356,7 @@ schemaUpdateNow: 1 """ self.transaction_start() try: - seq = super(SamDB, self).sequence_number(seq_type) + seq = super().sequence_number(seq_type) except: self.transaction_cancel() raise diff --git a/python/samba/subunit/run.py b/python/samba/subunit/run.py index 4cf42b05eaf..dc3f9316fcb 100755 --- a/python/samba/subunit/run.py +++ b/python/samba/subunit/run.py @@ -77,13 +77,13 @@ class TestProtocolClient(unittest.TestResult): def startTest(self, test): """Mark a test as starting its test run.""" - super(TestProtocolClient, self).startTest(test) + super().startTest(test) self._stream.write("test: " + test.id() + "\n") self._stream.flush() def stopTest(self, test): """Mark a test as having finished its test run.""" - super(TestProtocolClient, self).stopTest(test) + super().stopTest(test) self.writeOutcome(test) def writeOutcome(self, test): @@ -359,7 +359,7 @@ class HookedTestResultDecorator(TestResultDecorator): """A TestResult which calls a hook on every event.""" def __init__(self, decorated): - self.super = super(HookedTestResultDecorator, self) + self.super = super() self.super.__init__(decorated) def startTest(self, test): @@ -430,7 +430,7 @@ class AutoTimingTestResultDecorator(HookedTestResultDecorator): def __init__(self, decorated): self._time = None - super(AutoTimingTestResultDecorator, self).__init__(decorated) + super().__init__(decorated) def _before_event(self): time = self._time -- 2.47.3