From 0a97ad618ce6dfa952044088a28fb385e2138c7d Mon Sep 17 00:00:00 2001 From: Nex Sabre Date: Sat, 10 Jul 2021 10:05:54 +0200 Subject: [PATCH] Add info to diff (#32) * Requirements separation and organize imports in tests * Correct GH's action * Add more information to the show_diff: now scapy_helper can print module name for origin of the packet for decode. * Add more information to the show_diff: now scapy_helper can print module name for origin of the packet for decode. * Bump version and update CHANGELOG * Reformat with Black --- CHANGELOG | 3 +++ README.md | 4 ++-- scapy_helper/main.py | 24 ++++++++++++++++++++++-- setup.py | 2 +- 4 files changed, 28 insertions(+), 5 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 8f56e5b..077da2a 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,6 @@ +v0.14.0 +* Add information about origin of the module in `show_diff`. It should help in recognition of the packets. + v0.13.0 * Add assertion definitions: "assert_hex_equal", "assert_hex_not_equal", "assert_hex_len_equal", "assert_hex_len_not_equal", "assert_bytes_equal", "assert_bytes_not_equal" diff --git a/README.md b/README.md index 46e94de..063fa15 100644 --- a/README.md +++ b/README.md @@ -29,8 +29,8 @@ show_diff(Ether(), second_ether) # WARN:: Frame len is not the same # WARN:: Second row is longer by the 4B # -# __ __ ff __ __ ff __ 00 00 00 00 00 __ __ XX XX XX XX | len: 14B -# __ __ fc __ __ fa __ 11 11 11 11 11 __ __ 11 11 00 22 | len: 18B +# scapy | __ __ ff __ __ ff __ 00 00 00 00 00 __ __ XX XX XX XX | len: 14B +# hex | __ __ fc __ __ fa __ 11 11 11 11 11 __ __ 11 11 00 22 | len: 18B # # Not equal at 11B diff --git a/scapy_helper/main.py b/scapy_helper/main.py index 34bb461..574d020 100644 --- a/scapy_helper/main.py +++ b/scapy_helper/main.py @@ -133,6 +133,13 @@ def __process_char(char): def show_diff(first, second, index=False, extend=False, empty_char="XX"): + def get_name(module): + if isinstance(module, str): + return "hex" + return module.__module__.split(".")[0] + + _first_module_name, _second_module_name = get_name(first), get_name(second) + first_row, second_row, indexes_of_diff = diff(first, second) first_row_len_bytes = count_bytes(first_row) second_row_len_bytes = count_bytes(second_row) @@ -144,8 +151,21 @@ def show_diff(first, second, index=False, extend=False, empty_char="XX"): if element == " ": row[idx] = empty_char - print("%s | len: %sB" % (" ".join(first_row), first_row_len_bytes)) - print("%s | len: %sB" % (" ".join(second_row), second_row_len_bytes)) + max_fill = max((len(_first_module_name), len(_second_module_name))) + + print( + "%s | %s | len: %sB" + % (_first_module_name.ljust(max_fill), " ".join(first_row), first_row_len_bytes) + ) + print( + "%s | %s | len: %sB" + % ( + _second_module_name.ljust(max_fill), + " ".join(second_row), + second_row_len_bytes, + ) + ) + if index and indexes_of_diff: str_bar = ( " " * first_row_len_bytes diff --git a/setup.py b/setup.py index 5e8d218..594e86f 100644 --- a/setup.py +++ b/setup.py @@ -10,7 +10,7 @@ long_description_content_type="text/markdown", author="Nex Sabre", author_email="nexsabre@protonmail.com", - version="0.13.0", + version="0.14.0", url="https://github.com/NexSabre/scapy_helper", packages=find_packages(), classifiers=[