From a6db29dc7c1ff4e3a623652dbc396bee09863430 Mon Sep 17 00:00:00 2001 From: Michael Dong Date: Thu, 18 Oct 2018 14:39:59 -0500 Subject: [PATCH] Bug fixes related to python 3 changes Change-Id: I048bb19cf456281521883eb1500832343d72fb97 --- syntribos/clients/http/parser.py | 8 ++++---- syntribos/runner.py | 2 +- syntribos/tests/fuzz/base_fuzz.py | 2 +- syntribos/utils/string_utils.py | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/syntribos/clients/http/parser.py b/syntribos/clients/http/parser.py index 25e09196..8c8c2207 100644 --- a/syntribos/clients/http/parser.py +++ b/syntribos/clients/http/parser.py @@ -36,7 +36,7 @@ _string_var_objs = {} class RequestCreator(object): ACTION_FIELD = "ACTION_FIELD:" - EXTERNAL = r"CALL_EXTERNAL\|([^:]+?):([^:]+?):([^|]+?)\|" + EXTERNAL = r"CALL_EXTERNAL\|([^:]+?):([^:]+?)(?::([^|]+?))?\|" METAVAR = r"(\|[^\|]*\|)" FUNC_WITH_ARGS = r"([^:]+):([^:]+):(\[.+\])" FUNC_NO_ARGS = r"([^:]+):([^:]+)" @@ -85,9 +85,9 @@ class RequestCreator(object): """ if not cls.meta_vars: msg = ("Template contains reference to meta variable of the form " - "\'|variable|\', but no meta.json file is found in the" + "'|{}|', but no meta.json file is found in the" "templates directory. Check your templates and the " - "documentation on how to resolve this") + "documentation on how to resolve this".format(var)) raise TemplateParseException(msg) if var not in cls.meta_vars: @@ -326,7 +326,7 @@ class RequestCreator(object): break dot_path = match.group(1) func_name = match.group(2) - arg_list = match.group(3) + arg_list = match.group(3) or "[]" mod = importlib.import_module(dot_path) func = getattr(mod, func_name) args = json.loads(arg_list) diff --git a/syntribos/runner.py b/syntribos/runner.py index 8563a73d..045711ac 100644 --- a/syntribos/runner.py +++ b/syntribos/runner.py @@ -415,7 +415,7 @@ class Runner(object): failures = result.stats['unique_failures'] - last_failures errors = result.stats['errors'] - last_errors failures_str = cli.colorize_by_percent( - failures, total_tests, "red") + failures, total_tests) if errors: errors_str = cli.colorize(errors, "red") diff --git a/syntribos/tests/fuzz/base_fuzz.py b/syntribos/tests/fuzz/base_fuzz.py index 8f4f6ed0..37bc30cf 100644 --- a/syntribos/tests/fuzz/base_fuzz.py +++ b/syntribos/tests/fuzz/base_fuzz.py @@ -50,7 +50,7 @@ class BaseFuzzTestCase(base.BaseTestCase): else: path = os.path.join(payloads, file_name or cls.data_key) with open(path, "rb") as fp: - return fp.read().splitlines() + return str(fp.read()).splitlines() except (IOError, AttributeError, TypeError) as e: LOG.error("Exception raised: {}".format(e)) print("\nPayload file for test '{}' not readable, " diff --git a/syntribos/utils/string_utils.py b/syntribos/utils/string_utils.py index a8ecaeea..8d4b5a81 100644 --- a/syntribos/utils/string_utils.py +++ b/syntribos/utils/string_utils.py @@ -87,7 +87,7 @@ def compress(content, threshold=512): compressed_data = base64.b64encode( zlib.compress(bytes(content.encode("utf-8")))) if not six.PY2: - compressed_data = compressed_data.decode("utf-8") + compressed_data = str(compressed_data.decode("utf-8")) return pprint.pformat( "\n***Content compressed by Syntribos.***" "\nFirst fifty characters of content:\n"