Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions nettacker/core/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,7 @@ def print_logo():
OWASP Nettacker Logo
"""
log.write_to_api_console(
open(Config.path.logo_file)
.read()
.format(
Config.path.logo_file.read_text(encoding="utf-8").format(
cyan=TerminalCodes.CYAN.value,
red=TerminalCodes.RED.value,
rst=TerminalCodes.RESET.value,
Expand Down
2 changes: 1 addition & 1 deletion nettacker/core/fuzzer.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@


def read_from_file(file_path):
return open(Config.path.payloads_dir / file_path).read().split("\n")
return (Config.path.payloads_dir / file_path).read_text(encoding="utf-8").split("\n")
4 changes: 3 additions & 1 deletion nettacker/core/messages.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import sys
from io import StringIO
from pathlib import Path

import yaml

Expand All @@ -20,7 +21,8 @@ def application_language():


def load_yaml(filename):
return yaml.load(StringIO(open(filename, "r").read()), Loader=yaml.FullLoader)
yaml_text = Path(filename).read_text(encoding="utf-8")
return yaml.load(StringIO(yaml_text), Loader=yaml.FullLoader)


def get_languages():
Expand Down
2 changes: 1 addition & 1 deletion nettacker/core/utils/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ def string_to_bytes(string):
def fuzzer_function_read_file_as_array(filename):
from nettacker.config import PathConfig

return open(PathConfig().payloads_dir / filename).read().split("\n")
return (PathConfig().payloads_dir / filename).read_text(encoding="utf-8").split("\n")


def apply_data_functions(data):
Expand Down
4 changes: 2 additions & 2 deletions nettacker/lib/compare_report/engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ def build_report(compare_result):
Compare report in HTML
"""
data = (
open(Config.path.web_static_dir / "report/compare_report.html")
.read()
(Config.path.web_static_dir / "report/compare_report.html")
.read_text(encoding="utf-8")
.replace("__data_will_locate_here__", json.dumps(compare_result))
)
return data
4 changes: 2 additions & 2 deletions nettacker/lib/graph/d3_tree_v1/engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ def start(events):
d3_structure["children"].append({"name": target, "children": children_array})

data = (
open(Config.path.web_static_dir / "report/d3_tree_v1.html")
.read()
(Config.path.web_static_dir / "report/d3_tree_v1.html")
.read_text(encoding="utf-8")
.replace("__data_will_locate_here__", escape_for_html_js(json.dumps(d3_structure)))
.replace("__title_to_replace__", messages("pentest_graphs"))
.replace("__description_to_replace__", messages("graph_message"))
Expand Down
17 changes: 12 additions & 5 deletions nettacker/lib/html_log/log_data.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
from pathlib import Path

from nettacker.config import Config

css_1 = open(Config.path.web_static_dir / "report/html_table.css").read()
json_parse_js = open(Config.path.web_static_dir / "report/json_parse.js").read()
table_end = open(Config.path.web_static_dir / "report/table_end.html").read()
table_items = open(Config.path.web_static_dir / "report/table_items.html").read()
table_title = open(Config.path.web_static_dir / "report/table_title.html").read()

def read_static_text(path: Path) -> str:
return path.read_text(encoding="utf-8")
Comment on lines +6 to +7
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Add a docstring to read_static_text.
This is a public module-level function and should include a short docstring for maintainability and API clarity.

As per coding guidelines, "Keep functions small, use type hints where practical, and add docstrings for public APIs".

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@nettacker/lib/html_log/log_data.py` around lines 6 - 7, Add a concise
docstring to the public function read_static_text(path: Path) describing its
purpose (reads and returns the text contents of a file), the parameter (path:
Path — file path to read), the return value (str — file contents decoded as
UTF-8), and any noteworthy behavior (uses encoding="utf-8"). Place the docstring
immediately below the def read_static_text(...) signature following standard
triple-quoted style.



css_1 = read_static_text(Config.path.web_static_dir / "report/html_table.css")
json_parse_js = read_static_text(Config.path.web_static_dir / "report/json_parse.js")
table_end = read_static_text(Config.path.web_static_dir / "report/table_end.html")
table_items = read_static_text(Config.path.web_static_dir / "report/table_items.html")
table_title = read_static_text(Config.path.web_static_dir / "report/table_title.html")