diff --git a/contrib/python/compare_RecordsConfigcc.py b/contrib/python/compare_RecordsConfigcc.py index 8296ac3d243..2eebce30967 100755 --- a/contrib/python/compare_RecordsConfigcc.py +++ b/contrib/python/compare_RecordsConfigcc.py @@ -22,7 +22,7 @@ try: src_dir = sys.argv[1] except IndexError: - print("Usage: %s [trafficserver_source_dir]" % sys.argv[0]) + print(f"Usage: {sys.argv[0]} [trafficserver_source_dir]") print("Compares values in RecordsConfig.cc with the default records.config file") sys.exit(1) @@ -45,7 +45,7 @@ rc_doc = {} # documented values # Process RecordsConfig.cc -with open("%s/mgmt/RecordsConfig.cc" % src_dir) as fh: +with open(f"{src_dir}/mgmt/RecordsConfig.cc") as fh: cc_re = re.compile(r'\{RECT_(?:CONFIG|LOCAL), "([^"]+)", RECD_([A-Z]+), (.+?), ') for line in fh: m = cc_re.search(line) @@ -56,7 +56,7 @@ rc_cc[m.group(1)] = (m.group(2), value) # Process records.config.default.in -with open("%s/configs/records.config.default.in" % src_dir) as fh: +with open(f"{src_dir}/configs/records.config.default.in") as fh: in_re = re.compile(r'(?:CONFIG|LOCAL) (\S+)\s+(\S+)\s+(\S+)') for line in fh: m = in_re.match(line) @@ -65,7 +65,7 @@ # Process records.config documentation. # eg. .. ts:cv:: CONFIG proxy.config.proxy_binary STRING traffic_server -with open("%s/doc/admin-guide/files/records.config.en.rst" % src_dir) as fh: +with open(f"{src_dir}/doc/admin-guide/files/records.config.en.rst") as fh: doc_re = re.compile(r'ts:cv:: CONFIG (\S+)\s+(\S+)\s+(\S+)') for line in fh: m = doc_re.search(line) @@ -109,4 +109,4 @@ print() print("Stale documentation:") for s in sorted(stale): - print("\t%s" % (s)) + print(f"\t{s}") diff --git a/contrib/python/compare_records_config.py b/contrib/python/compare_records_config.py index bd610a9b5d1..bd30df084f2 100755 --- a/contrib/python/compare_records_config.py +++ b/contrib/python/compare_records_config.py @@ -44,7 +44,7 @@ def parse_records_file(filename): try: settings[parts[1]] = parts[3] except IndexError: - sys.stderr.write("Skipping malformed line: %s\n" % line) + sys.stderr.write(f"Skipping malformed line: {line}\n") continue return settings @@ -61,7 +61,7 @@ def compare_settings(old, new): # Skip predefined values continue if old[key] != new[key]: - print("%s %s -> %s" % (key, old[key], new[key])) + print(f"{key} {old[key]} -> {new[key]}") if __name__ == '__main__': diff --git a/doc/checkvers.py b/doc/checkvers.py index e0ca9bc66a5..42884452beb 100644 --- a/doc/checkvers.py +++ b/doc/checkvers.py @@ -30,21 +30,21 @@ min_sphinx_version_info = (1, 7, 5) min_sphinx_version = '.'.join(str(x) for x in min_sphinx_version_info) - print('checking for sphinx version >= {0}... '.format(min_sphinx_version), end="") + print(f'checking for sphinx version >= {min_sphinx_version}... ', end="") # Need at least 1.5.1 to use svg # version >= 1.2 guarantees sphinx.version_info is available. try: import sphinx if 'version_info' in dir(sphinx): - print('Found Sphinx version {0}'.format(sphinx.version_info)) + print(f'Found Sphinx version {sphinx.version_info}') else: version = sphinx.__version__ - print('Found Sphinx version (old) {0}'.format(sphinx.__version__)) + print(f'Found Sphinx version (old) {sphinx.__version__}') sphinx.version_info = version.split('.') if sphinx.version_info < min_sphinx_version_info: - print('sphinx version is older than {0}'.format(min_sphinx_version)) + print(f'sphinx version is older than {min_sphinx_version}') sys.exit(1) except Exception as e: diff --git a/doc/conf.py b/doc/conf.py index 89de61cd34a..5159a82ec1b 100644 --- a/doc/conf.py +++ b/doc/conf.py @@ -89,7 +89,7 @@ # General information about the project. project = u'Apache Traffic Server' -copyright = u'{}, dev@trafficserver.apache.org'.format(date.today().year) +copyright = f'{date.today().year}, dev@trafficserver.apache.org' # The version info for the project you're documenting, acts as replacement for # |version| and |release|, also used in various other places throughout the diff --git a/plugins/experimental/ssl_session_reuse/tests/plug-load.test.py b/plugins/experimental/ssl_session_reuse/tests/plug-load.test.py index 10a6468f711..a144e55423d 100644 --- a/plugins/experimental/ssl_session_reuse/tests/plug-load.test.py +++ b/plugins/experimental/ssl_session_reuse/tests/plug-load.test.py @@ -37,23 +37,23 @@ server.addResponse("sessionfile.log", request_header, response_header) ts.Disk.records_config.update({ 'proxy.config.diags.debug.enabled': 1, - 'proxy.config.diags.debug.tags': '{0}'.format(pluginName), + 'proxy.config.diags.debug.tags': f'{pluginName}', }) ts.Disk.plugin_config.AddLine( - '# {1}/{0}.so {2}'.format(pluginName, path, configFile) + f'# {path}/{pluginName}.so {configFile}' ) ts.Disk.remap_config.AddLine( - 'map http://www.example.com http://127.0.0.1:{0}'.format(server.Variables.Port) + f'map http://www.example.com http://127.0.0.1:{server.Variables.Port}' ) -goldFile = os.path.join(Test.RunDirectory, "{0}.gold".format(pluginName)) +goldFile = os.path.join(Test.RunDirectory, f"{pluginName}.gold") with open(goldFile, 'w+') as jf: - jf.write("``loading plugin ``{0}.so``".format(pluginName)) + jf.write(f"``loading plugin ``{pluginName}.so``") # call localhost straight tr = Test.AddTestRun() -tr.Processes.Default.Command = 'curl --proxy 127.0.0.1:{0} "http://www.example.com" --verbose'.format(ts.Variables.port) +tr.Processes.Default.Command = f'curl --proxy 127.0.0.1:{ts.Variables.port} "http://www.example.com" --verbose' tr.Processes.Default.ReturnCode = 0 # time delay as proxy.config.http.wait_for_cache could be broken tr.Processes.Default.StartBefore(server, ready=When.PortOpen(server.Variables.Port)) diff --git a/plugins/experimental/traffic_dump/post_process.py b/plugins/experimental/traffic_dump/post_process.py index 0472cbc0735..2dea30ddbf2 100755 --- a/plugins/experimental/traffic_dump/post_process.py +++ b/plugins/experimental/traffic_dump/post_process.py @@ -189,7 +189,7 @@ def write_sessions(sessions, filename, indent): new_json["sessions"] = deepcopy(sessions) with open(filename, "w") as f: json.dump(new_json, f, ensure_ascii=False, indent=indent) - logging.debug("{} has {} sessions".format(filename, len(sessions))) + logging.debug(f"{filename} has {len(sessions)} sessions") class ParseJSONError(PostProcessError): @@ -274,11 +274,11 @@ def readAndCombine(replay_dir, num_sessions_per_file, indent, fabricate_proxy_re session_count += 1 transaction_count += len(session["transactions"]) if len(sessions) >= num_sessions_per_file: - write_sessions(sessions, "{}/{}_{}.json".format(out_dir, base_name, batch_count), indent) + write_sessions(sessions, f"{out_dir}/{base_name}_{batch_count}.json", indent) sessions = [] batch_count += 1 if sessions: - write_sessions(sessions, "{}/{}_{}.json".format(out_dir, base_name, batch_count), indent) + write_sessions(sessions, f"{out_dir}/{base_name}_{batch_count}.json", indent) return session_count, transaction_count, error_count @@ -409,17 +409,17 @@ def main(): transaction_count += count_tuple[1] for e in count_tuple[2]: errors[e] += count_tuple[2][e] - summary = "Total {} sessions and {} transactions.".format(session_count, transaction_count) + summary = f"Total {session_count} sessions and {transaction_count} transactions." logging.info(summary) if errors: logging.info("Total errors:") for e in errors: - logging.info("{}: {}".format(e, errors[e])) + logging.info(f"{e}: {errors[e]}") else: logging.info("Total errors: 0") - with open("{}/summary.txt".format(args.out_dir), "w", encoding="ascii") as f: - f.write("{}\n".format(summary)) + with open(f"{args.out_dir}/summary.txt", "w", encoding="ascii") as f: + f.write(f"{summary}\n") if __name__ == "__main__":