This changes all the python2 files to python3. Signed-off-by: Shekhar Sharma <shekhar250198@xxxxxxxxx> --- py/nftables.py | 2 +- tests/json_echo/run-test.py | 40 ++++++++++++++++++------------------- tests/py/nft-test.py | 32 ++++++++++++++--------------- 3 files changed, 37 insertions(+), 37 deletions(-) diff --git a/py/nftables.py b/py/nftables.py index 33cd2dfd..6503aedd 100644 --- a/py/nftables.py +++ b/py/nftables.py @@ -297,7 +297,7 @@ class Nftables: val = self.nft_ctx_output_get_debug(self.__ctx) names = [] - for n,v in self.debug_flags.items(): + for n,v in list(self.debug_flags.items()): if val & v: names.append(n) val &= ~v diff --git a/tests/json_echo/run-test.py b/tests/json_echo/run-test.py index 0132b139..330034a0 100755 --- a/tests/json_echo/run-test.py +++ b/tests/json_echo/run-test.py @@ -13,8 +13,8 @@ from nftables import Nftables os.chdir(TESTS_PATH + "/../..") if not os.path.exists('src/.libs/libnftables.so'): - print "The nftables library does not exist. " \ - "You need to build the project." + print("The nftables library does not exist. " \ + "You need to build the project.") sys.exit(1) nftables = Nftables(sofile = 'src/.libs/libnftables.so') @@ -79,12 +79,12 @@ add_quota = { "add": { # helper functions def exit_err(msg): - print "Error: %s" % msg + print("Error: %s" % msg) sys.exit(1) def exit_dump(e, obj): - print "FAIL: %s" % e - print "Output was:" + print("FAIL: %s" % e) + print("Output was:") json.dumps(out, sort_keys = True, indent = 4, separators = (',', ': ')) sys.exit(1) @@ -118,12 +118,12 @@ def get_handle(output, search): else: data = item - k = search.keys()[0] + k = list(search.keys())[0] if not k in data: continue found = True - for key in search[k].keys(): + for key in list(search[k].keys()): if key == "handle": continue if not key in data[k] or search[k][key] != data[k][key]: @@ -140,7 +140,7 @@ def get_handle(output, search): do_flush() -print "Adding table t" +print("Adding table t") out = do_command(add_table) handle = get_handle(out, add_table["add"]) @@ -152,7 +152,7 @@ if handle != handle_cmp: add_table["add"]["table"]["handle"] = handle -print "Adding chain c" +print("Adding chain c") out = do_command(add_chain) handle = get_handle(out, add_chain["add"]) @@ -164,7 +164,7 @@ if handle != handle_cmp: add_chain["add"]["chain"]["handle"] = handle -print "Adding set s" +print("Adding set s") out = do_command(add_set) handle = get_handle(out, add_set["add"]) @@ -176,7 +176,7 @@ if handle != handle_cmp: add_set["add"]["set"]["handle"] = handle -print "Adding rule" +print("Adding rule") out = do_command(add_rule) handle = get_handle(out, add_rule["add"]) @@ -188,7 +188,7 @@ if handle != handle_cmp: add_rule["add"]["rule"]["handle"] = handle -print "Adding counter" +print("Adding counter") out = do_command(add_counter) handle = get_handle(out, add_counter["add"]) @@ -200,7 +200,7 @@ if handle != handle_cmp: add_counter["add"]["counter"]["handle"] = handle -print "Adding quota" +print("Adding quota") out = do_command(add_quota) handle = get_handle(out, add_quota["add"]) @@ -222,37 +222,37 @@ add_set["add"]["set"]["name"] = "s2" add_counter["add"]["counter"]["name"] = "c2" add_quota["add"]["quota"]["name"] = "q2" -print "Adding table t2" +print("Adding table t2") out = do_command(add_table) handle = get_handle(out, add_table["add"]) if handle == add_table["add"]["table"]["handle"]: exit_err("handle not changed in re-added table!") -print "Adding chain c2" +print("Adding chain c2") out = do_command(add_chain) handle = get_handle(out, add_chain["add"]) if handle == add_chain["add"]["chain"]["handle"]: exit_err("handle not changed in re-added chain!") -print "Adding set s2" +print("Adding set s2") out = do_command(add_set) handle = get_handle(out, add_set["add"]) if handle == add_set["add"]["set"]["handle"]: exit_err("handle not changed in re-added set!") -print "Adding rule again" +print("Adding rule again") out = do_command(add_rule) handle = get_handle(out, add_rule["add"]) if handle == add_rule["add"]["rule"]["handle"]: exit_err("handle not changed in re-added rule!") -print "Adding counter c2" +print("Adding counter c2") out = do_command(add_counter) handle = get_handle(out, add_counter["add"]) if handle == add_counter["add"]["counter"]["handle"]: exit_err("handle not changed in re-added counter!") -print "Adding quota q2" +print("Adding quota q2") out = do_command(add_quota) handle = get_handle(out, add_quota["add"]) if handle == add_quota["add"]["quota"]["handle"]: @@ -269,7 +269,7 @@ add_quota["add"]["quota"]["name"] = "q" do_flush() -print "doing multi add" +print("doing multi add") # XXX: Add table separately, otherwise this triggers cache bug out = do_command(add_table) thandle = get_handle(out, add_table["add"]) diff --git a/tests/py/nft-test.py b/tests/py/nft-test.py index 1c0afd0e..35c5d0e5 100755 --- a/tests/py/nft-test.py +++ b/tests/py/nft-test.py @@ -436,7 +436,7 @@ def set_delete(table, filename=None, lineno=None): ''' Deletes set and its content. ''' - for set_name in all_set.keys(): + for set_name in list(all_set.keys()): # Check if exists the set if not set_exist(set_name, table, filename, lineno): reason = "The set %s does not exist, " \ @@ -1002,9 +1002,9 @@ def execute_cmd(cmd, filename, lineno, stdout_log=False, debug=False): :param debug: temporarily set these debug flags ''' global log_file - print >> log_file, "command: %s" % cmd + print("command: %s" % cmd, file= log_file) if debug_option: - print cmd + print(cmd) if debug: debug_old = nftables.get_debug() @@ -1198,7 +1198,7 @@ def run_test_file(filename, force_all_family_option, specific_file): sys.stdout.flush() if signal_received == 1: - print "\nSignal received. Cleaning up and Exitting..." + print("\nSignal received. Cleaning up and Exitting...") cleanup_on_exit() sys.exit(0) @@ -1305,13 +1305,13 @@ def run_test_file(filename, force_all_family_option, specific_file): if specific_file: if force_all_family_option: - print print_result_all(filename, tests, total_warning, total_error, - total_unit_run) + print(print_result_all(filename, tests, total_warning, total_error, + total_unit_run)) else: - print print_result(filename, tests, total_warning, total_error) + print(print_result(filename, tests, total_warning, total_error)) else: if tests == passed and tests > 0: - print filename + ": " + Colors.GREEN + "OK" + Colors.ENDC + print(filename + ": " + Colors.GREEN + "OK" + Colors.ENDC) f.close() del table_list[:] @@ -1353,15 +1353,15 @@ def main(): signal.signal(signal.SIGTERM, signal_handler) if os.getuid() != 0: - print "You need to be root to run this, sorry" + print("You need to be root to run this, sorry") return # Change working directory to repository root os.chdir(TESTS_PATH + "/../..") if not os.path.exists('src/.libs/libnftables.so'): - print "The nftables library does not exist. " \ - "You need to build the project." + print("The nftables library does not exist. " \ + "You need to build the project.") return global nftables @@ -1411,18 +1411,18 @@ def main(): run_total += file_unit_run if test_files == 0: - print "No test files to run" + print("No test files to run") else: if not specific_file: if force_all_family_option: - print "%d test files, %d files passed, %d unit tests, " \ + print("%d test files, %d files passed, %d unit tests, " \ "%d total executed, %d error, %d warning" \ % (test_files, files_ok, tests, run_total, errors, - warnings) + warnings)) else: - print "%d test files, %d files passed, %d unit tests, " \ + print("%d test files, %d files passed, %d unit tests, " \ "%d error, %d warning" \ - % (test_files, files_ok, tests, errors, warnings) + % (test_files, files_ok, tests, errors, warnings)) if __name__ == '__main__': -- 2.21.0.windows.1