diff options
author | Björn Jacke <bj@sernet.de> | 2019-08-25 23:05:10 +0200 |
---|---|---|
committer | Bjoern Jacke <bjacke@samba.org> | 2019-09-24 12:22:44 +0000 |
commit | 1825a7f4e2a39d03f01da37b68ba4f65dbafd04a (patch) | |
tree | 2dad60a273f7560a084e3105a41329912d8bd690 /python | |
parent | 4c34a2d72569f31d59b904c3ca1c140f6084b3dd (diff) | |
download | samba-1825a7f4e2a39d03f01da37b68ba4f65dbafd04a.tar.gz |
kcc_utils.py: avoid inefficient string concatenations
Signed-off-by: Bjoern Jacke <bjacke@samba.org>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
Diffstat (limited to 'python')
-rw-r--r-- | python/samba/kcc/kcc_utils.py | 195 |
1 files changed, 92 insertions, 103 deletions
diff --git a/python/samba/kcc/kcc_utils.py b/python/samba/kcc/kcc_utils.py index 3e9a988b778..e0712e49c82 100644 --- a/python/samba/kcc/kcc_utils.py +++ b/python/samba/kcc/kcc_utils.py @@ -66,9 +66,9 @@ class NamingContext(object): def __str__(self): '''Debug dump string output of class''' - text = "%s:" % (self.__class__.__name__,) - text = text + "\n\tnc_dnstr=%s" % self.nc_dnstr - text = text + "\n\tnc_guid=%s" % str(self.nc_guid) + text = "%s:" % (self.__class__.__name__,) +\ + "\n\tnc_dnstr=%s" % self.nc_dnstr +\ + "\n\tnc_guid=%s" % str(self.nc_guid) if self.nc_sid is None: text = text + "\n\tnc_sid=<absent>" @@ -200,20 +200,16 @@ class NCReplica(NamingContext): def __str__(self): '''Debug dump string output of class''' - text = "%s:" % self.__class__.__name__ - text = text + "\n\tdsa_dnstr=%s" % self.rep_dsa_dnstr - text = text + "\n\tdsa_guid=%s" % self.rep_dsa_guid - text = text + "\n\tdefault=%s" % self.rep_default - text = text + "\n\tro=%s" % self.rep_ro - text = text + "\n\tpartial=%s" % self.rep_partial - text = text + "\n\tpresent=%s" % self.is_present() - text = text + "\n\tfsmo_role_owner=%s" % self.rep_fsmo_role_owner - - for rep in self.rep_repsFrom: - text = text + "\n%s" % rep - - for rep in self.rep_repsTo: - text = text + "\n%s" % rep + text = "%s:" % self.__class__.__name__ +\ + "\n\tdsa_dnstr=%s" % self.rep_dsa_dnstr +\ + "\n\tdsa_guid=%s" % self.rep_dsa_guid +\ + "\n\tdefault=%s" % self.rep_default +\ + "\n\tro=%s" % self.rep_ro +\ + "\n\tpartial=%s" % self.rep_partial +\ + "\n\tpresent=%s" % self.is_present() +\ + "\n\tfsmo_role_owner=%s" % self.rep_fsmo_role_owner +\ + "".join("\n%s" % rep for rep in self.rep_repsFrom) +\ + "".join("\n%s" % rep for rep in self.rep_repsTo) return "%s\n%s" % (NamingContext.__str__(self), text) @@ -589,16 +585,15 @@ class DirectoryServiceAgent(object): if self.dsa_ivid is not None: text = text + "\n\tdsa_ivid=%s" % str(self.dsa_ivid) - text = text + "\n\tro=%s" % self.is_ro() - text = text + "\n\tgc=%s" % self.is_gc() - text = text + "\n\tistg=%s" % self.is_istg() - - text = text + "\ncurrent_replica_table:" - text = text + "\n%s" % self.dumpstr_current_replica_table() - text = text + "\nneeded_replica_table:" - text = text + "\n%s" % self.dumpstr_needed_replica_table() - text = text + "\nconnect_table:" - text = text + "\n%s" % self.dumpstr_connect_table() + text += "\n\tro=%s" % self.is_ro() +\ + "\n\tgc=%s" % self.is_gc() +\ + "\n\tistg=%s" % self.is_istg() +\ + "\ncurrent_replica_table:" +\ + "\n%s" % self.dumpstr_current_replica_table() +\ + "\nneeded_replica_table:" +\ + "\n%s" % self.dumpstr_needed_replica_table() +\ + "\nconnect_table:" +\ + "\n%s" % self.dumpstr_connect_table() return text @@ -919,39 +914,38 @@ class NTDSConnection(object): def __str__(self): '''Debug dump string output of NTDSConnection object''' - text = "%s:\n\tdn=%s" % (self.__class__.__name__, self.dnstr) - text = text + "\n\tenabled=%s" % self.enabled - text = text + "\n\tto_be_added=%s" % self.to_be_added - text = text + "\n\tto_be_deleted=%s" % self.to_be_deleted - text = text + "\n\tto_be_modified=%s" % self.to_be_modified - text = text + "\n\toptions=0x%08X" % self.options - text = text + "\n\tsystem_flags=0x%08X" % self.system_flags - text = text + "\n\twhenCreated=%d" % self.whenCreated - text = text + "\n\ttransport_dn=%s" % self.transport_dnstr + text = "%s:\n\tdn=%s" % (self.__class__.__name__, self.dnstr) +\ + "\n\tenabled=%s" % self.enabled +\ + "\n\tto_be_added=%s" % self.to_be_added +\ + "\n\tto_be_deleted=%s" % self.to_be_deleted +\ + "\n\tto_be_modified=%s" % self.to_be_modified +\ + "\n\toptions=0x%08X" % self.options +\ + "\n\tsystem_flags=0x%08X" % self.system_flags +\ + "\n\twhenCreated=%d" % self.whenCreated +\ + "\n\ttransport_dn=%s" % self.transport_dnstr if self.guid is not None: - text = text + "\n\tguid=%s" % str(self.guid) + text += "\n\tguid=%s" % str(self.guid) if self.transport_guid is not None: - text = text + "\n\ttransport_guid=%s" % str(self.transport_guid) + text += "\n\ttransport_guid=%s" % str(self.transport_guid) text = text + "\n\tfrom_dn=%s" % self.from_dnstr if self.schedule is not None: - text += "\n\tschedule.size=%s" % self.schedule.size - text += "\n\tschedule.bandwidth=%s" % self.schedule.bandwidth - text += ("\n\tschedule.numberOfSchedules=%s" % + text += "\n\tschedule.size=%s" % self.schedule.size +\ + "\n\tschedule.bandwidth=%s" % self.schedule.bandwidth +\ + ("\n\tschedule.numberOfSchedules=%s" % self.schedule.numberOfSchedules) for i, header in enumerate(self.schedule.headerArray): text += ("\n\tschedule.headerArray[%d].type=%d" % - (i, header.type)) - text += ("\n\tschedule.headerArray[%d].offset=%d" % - (i, header.offset)) - text += "\n\tschedule.dataArray[%d].slots[ " % i - for slot in self.schedule.dataArray[i].slots: - text = text + "0x%X " % slot - text = text + "]" + (i, header.type)) +\ + ("\n\tschedule.headerArray[%d].offset=%d" % + (i, header.offset)) +\ + "\n\tschedule.dataArray[%d].slots[ " % i +\ + "".join("0x%X " % slot for slot in self.schedule.dataArray[i].slots) +\ + "]" return text @@ -1458,12 +1452,10 @@ class Partition(NamingContext): def __str__(self): '''Debug dump string output of class''' - text = "%s" % NamingContext.__str__(self) - text = text + "\n\tpartdn=%s" % self.partstr - for k in self.rw_location_list: - text = text + "\n\tmsDS-NC-Replica-Locations=%s" % k - for k in self.ro_location_list: - text = text + "\n\tmsDS-NC-RO-Replica-Locations=%s" % k + text = "%s" % NamingContext.__str__(self) +\ + "\n\tpartdn=%s" % self.partstr +\ + "".join("\n\tmsDS-NC-Replica-Locations=%s" % k for k in self.rw_location_list) +\ + "".join("\n\tmsDS-NC-RO-Replica-Locations=%s" % k for k in self.ro_location_list) return text @@ -1764,11 +1756,11 @@ class Site(object): def __str__(self): '''Debug dump string output of class''' - text = "%s:" % self.__class__.__name__ - text = text + "\n\tdn=%s" % self.site_dnstr - text = text + "\n\toptions=0x%X" % self.site_options - text = text + "\n\ttopo_generator=%s" % self.site_topo_generator - text = text + "\n\ttopo_failover=%d" % self.site_topo_failover + text = "%s:" % self.__class__.__name__ +\ + "\n\tdn=%s" % self.site_dnstr +\ + "\n\toptions=0x%X" % self.site_options +\ + "\n\ttopo_generator=%s" % self.site_topo_generator +\ + "\n\ttopo_failover=%d" % self.site_topo_failover for key, dsa in self.dsa_table.items(): text = text + "\n%s" % dsa return text @@ -1792,9 +1784,9 @@ class GraphNode(object): self.edge_from = [] def __str__(self): - text = "%s:" % self.__class__.__name__ - text = text + "\n\tdsa_dnstr=%s" % self.dsa_dnstr - text = text + "\n\tmax_edges=%d" % self.max_edges + text = "%s:" % self.__class__.__name__ +\ + "\n\tdsa_dnstr=%s" % self.dsa_dnstr +\ + "\n\tmax_edges=%d" % self.max_edges for i, edge in enumerate(self.edge_from): if isinstance(edge, str): @@ -1894,13 +1886,12 @@ class Transport(object): def __str__(self): '''Debug dump string output of Transport object''' - text = "%s:\n\tdn=%s" % (self.__class__.__name__, self.dnstr) - text = text + "\n\tguid=%s" % str(self.guid) - text = text + "\n\toptions=%d" % self.options - text = text + "\n\taddress_attr=%s" % self.address_attr - text = text + "\n\tname=%s" % self.name - for dnstr in self.bridgehead_list: - text = text + "\n\tbridgehead_list=%s" % dnstr + text = "%s:\n\tdn=%s" % (self.__class__.__name__, self.dnstr) +\ + "\n\tguid=%s" % str(self.guid) +\ + "\n\toptions=%d" % self.options +\ + "\n\taddress_attr=%s" % self.address_attr +\ + "\n\tname=%s" % self.name +\ + "".join("\n\tbridgehead_list=%s" % dnstr for dnstr in self.bridgehead_list) return text @@ -2006,25 +1997,24 @@ class RepsFromTo(object): def __str__(self): '''Debug dump string output of class''' - text = "%s:" % self.__class__.__name__ - text += "\n\tdnstr=%s" % self.nc_dnstr - text += "\n\tupdate_flags=0x%X" % self.update_flags - text += "\n\tversion=%d" % self.version - text += "\n\tsource_dsa_obj_guid=%s" % self.source_dsa_obj_guid - text += ("\n\tsource_dsa_invocation_id=%s" % - self.source_dsa_invocation_id) - text += "\n\ttransport_guid=%s" % self.transport_guid - text += "\n\treplica_flags=0x%X" % self.replica_flags - text += ("\n\tconsecutive_sync_failures=%d" % - self.consecutive_sync_failures) - text += "\n\tlast_success=%s" % self.last_success - text += "\n\tlast_attempt=%s" % self.last_attempt - text += "\n\tdns_name1=%s" % self.dns_name1 - text += "\n\tdns_name2=%s" % self.dns_name2 - text += "\n\tschedule[ " - for slot in self.schedule: - text += "0x%X " % slot - text += "]" + text = "%s:" % self.__class__.__name__ +\ + "\n\tdnstr=%s" % self.nc_dnstr +\ + "\n\tupdate_flags=0x%X" % self.update_flags +\ + "\n\tversion=%d" % self.version +\ + "\n\tsource_dsa_obj_guid=%s" % self.source_dsa_obj_guid +\ + ("\n\tsource_dsa_invocation_id=%s" % + self.source_dsa_invocation_id) +\ + "\n\ttransport_guid=%s" % self.transport_guid +\ + "\n\treplica_flags=0x%X" % self.replica_flags +\ + ("\n\tconsecutive_sync_failures=%d" % + self.consecutive_sync_failures) +\ + "\n\tlast_success=%s" % self.last_success +\ + "\n\tlast_attempt=%s" % self.last_attempt +\ + "\n\tdns_name1=%s" % self.dns_name1 +\ + "\n\tdns_name2=%s" % self.dns_name2 +\ + "\n\tschedule[ " +\ + "".join("0x%X " % slot for slot in self.schedule) +\ + "]" return text @@ -2138,27 +2128,26 @@ class SiteLink(object): def __str__(self): '''Debug dump string output of Transport object''' - text = "%s:\n\tdn=%s" % (self.__class__.__name__, self.dnstr) - text = text + "\n\toptions=%d" % self.options - text = text + "\n\tsystem_flags=%d" % self.system_flags - text = text + "\n\tcost=%d" % self.cost - text = text + "\n\tinterval=%s" % self.interval + text = "%s:\n\tdn=%s" % (self.__class__.__name__, self.dnstr) +\ + "\n\toptions=%d" % self.options +\ + "\n\tsystem_flags=%d" % self.system_flags +\ + "\n\tcost=%d" % self.cost +\ + "\n\tinterval=%s" % self.interval if self.schedule is not None: - text += "\n\tschedule.size=%s" % self.schedule.size - text += "\n\tschedule.bandwidth=%s" % self.schedule.bandwidth - text += ("\n\tschedule.numberOfSchedules=%s" % + text += "\n\tschedule.size=%s" % self.schedule.size +\ + "\n\tschedule.bandwidth=%s" % self.schedule.bandwidth +\ + ("\n\tschedule.numberOfSchedules=%s" % self.schedule.numberOfSchedules) for i, header in enumerate(self.schedule.headerArray): text += ("\n\tschedule.headerArray[%d].type=%d" % - (i, header.type)) - text += ("\n\tschedule.headerArray[%d].offset=%d" % - (i, header.offset)) - text = text + "\n\tschedule.dataArray[%d].slots[ " % i - for slot in self.schedule.dataArray[i].slots: - text = text + "0x%X " % slot - text = text + "]" + (i, header.type)) +\ + ("\n\tschedule.headerArray[%d].offset=%d" % + (i, header.offset)) +\ + "\n\tschedule.dataArray[%d].slots[ " % i +\ + "".join("0x%X " % slot for slot in self.schedule.dataArray[i].slots) +\ + "]" for guid, dn in self.site_list: text = text + "\n\tsite_list=%s (%s)" % (guid, dn) |