Skip to content

Commit

Permalink
Linting + clearer hash dict key name
Browse files Browse the repository at this point in the history
  • Loading branch information
gdesmar committed Mar 11, 2024
1 parent ef1c224 commit f541c81
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 12 deletions.
3 changes: 1 addition & 2 deletions LnkParse3/exceptions.py
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
class LnkParserError(Exception):
...
class LnkParserError(Exception): ...
2 changes: 1 addition & 1 deletion LnkParse3/extra/terminal.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,5 @@ def size(self):

def as_dict(self):
tmp = super().as_dict()
tmp["sha256"] = hashlib.sha256(self.appended_data()).hexdigest()
tmp["appended_data_sha256"] = hashlib.sha256(self.appended_data()).hexdigest()
return tmp
2 changes: 1 addition & 1 deletion LnkParse3/extra/unknown.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@ def extra_data(self):

def as_dict(self):
tmp = super().as_dict()
tmp["sha256"] = hashlib.sha256(self.extra_data()).hexdigest()
tmp["extra_data_sha256"] = hashlib.sha256(self.extra_data()).hexdigest()
return tmp
15 changes: 9 additions & 6 deletions LnkParse3/lnk_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
__version__ = "1.3.3"

import json
import hashlib
import datetime
import argparse
from subprocess import list2cmdline
Expand Down Expand Up @@ -97,8 +96,6 @@ def cprint(text, level=0):
print(" " * (level * SPACING) + text) # add leading spaces

def nice_id(identifier):
if identifier.lower() in hashlib.algorithms_guaranteed:
return identifier.upper().replace("_", " ")
return identifier.capitalize().replace("_", " ")

# TODO recursive nice print
Expand Down Expand Up @@ -266,7 +263,9 @@ def nice_id(identifier):
cprint(f"{nice_id(key)}: {value}", 4)
else:
for key, value in extra_value.items():
if extra_key == "METADATA_PROPERTIES_BLOCK" and isinstance(value, list):
if extra_key == "METADATA_PROPERTIES_BLOCK" and isinstance(
value, list
):
cprint(f"{nice_id(key)}:", 3)
for storage in value:
cprint("Storage:", 4)
Expand All @@ -276,9 +275,13 @@ def nice_id(identifier):
for item in storage_value:
cprint("Property:", 6)
for item_key, item_value in item.items():
cprint(f"{nice_id(item_key)}: {item_value}", 7)
cprint(
f"{nice_id(item_key)}: {item_value}", 7
)
else:
cprint(f"{nice_id(storage_key)}: {storage_value}", 5)
cprint(
f"{nice_id(storage_key)}: {storage_value}", 5
)
else:
cprint(f"{nice_id(key)}: {value}", 3)

Expand Down
1 change: 1 addition & 0 deletions LnkParse3/text_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
the terminating null character are undefined and can have any value. The
undefined bytes MUST NOT be used.
"""

import warnings


Expand Down
2 changes: 1 addition & 1 deletion tests/json/unknown_target.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"data": {},
"extra": {
"TERMINAL_BLOCK": {
"sha256": "d64c62e65398d37cd27e11fd729fa102016a05ba67f5020e17dfbd3b857dd96e",
"appended_data_sha256": "d64c62e65398d37cd27e11fd729fa102016a05ba67f5020e17dfbd3b857dd96e",
"size": 67653
}
},
Expand Down
2 changes: 1 addition & 1 deletion tests/json/unknown_target.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,4 @@ Windows Shortcut Information:
EXTRA BLOCKS:
TERMINAL_BLOCK
Size: 67653
SHA256: d64c62e65398d37cd27e11fd729fa102016a05ba67f5020e17dfbd3b857dd96e
Appended data sha256: d64c62e65398d37cd27e11fd729fa102016a05ba67f5020e17dfbd3b857dd96e

0 comments on commit f541c81

Please sign in to comment.