Skip to content

Commit

Permalink
Add info to diff (#32)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
NexSabre authored Jul 10, 2021
1 parent f666212 commit 0a97ad6
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 5 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
24 changes: 22 additions & 2 deletions scapy_helper/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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=[
Expand Down

0 comments on commit 0a97ad6

Please sign in to comment.