Skip to content

Commit fbf6e49

Browse files
committed
Address Codacy findings on PR #96
* Bandit B110 (event_loop.py:189) — replace bare pass in CDPEventListener.stop()'s ws.close() except with a debug-log line so the cleanup failure is at least visible in WEBRunner.log. * Bandit B110 (_navigation_mixin.py:161) — same fix for the best-effort window-restore branch in _switch_to_window_by_attr. * Bandit B310 (event_loop.py:72) — annotate the urlopen call with '# nosec B310' plus a comment explaining the scheme is a fixed-literal http:// (only debugger_address host:port varies, no user-controlled scheme so no file:// risk).
1 parent 22cb377 commit fbf6e49

2 files changed

Lines changed: 10 additions & 5 deletions

File tree

je_web_runner/utils/cdp/event_loop.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,9 @@ def _query_page_ws_url(debugger_address: str) -> str:
6969
# the ``--remote-debugging-port``, is HTTP-only by browser design, and
7070
# binds to localhost. Forcing https here would simply fail to connect.
7171
url = f"http://{debugger_address}/json" # NOSONAR python:S5332 — DevTools endpoint is HTTP-only by design
72-
with urllib.request.urlopen(url, timeout=5) as response: # noqa: S310 — local devtools endpoint
72+
# Bandit B310: scheme is fixed-literal ``http://`` above, not user-controlled — only
73+
# ``debugger_address`` (host:port) varies, so no file:// or custom-scheme risk.
74+
with urllib.request.urlopen(url, timeout=5) as response: # nosec B310 # noqa: S310 — local devtools endpoint
7375
targets = json.loads(response.read())
7476
pages = [t for t in targets if t.get("type") == "page"]
7577
if not pages:
@@ -186,8 +188,8 @@ def stop(self, join_timeout: float = 2.0) -> None:
186188
if ws is not None:
187189
try:
188190
ws.close()
189-
except Exception: # noqa: BLE001 — best-effort
190-
pass
191+
except Exception as error: # noqa: BLE001 — best-effort cleanup
192+
web_runner_logger.debug(f"CDPEventListener ws.close failed: {error!r}")
191193
thread = self._thread
192194
self._thread = None
193195
if thread is not None and thread.is_alive():

je_web_runner/webdriver/_wrapper_mixins/_navigation_mixin.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,8 +158,11 @@ def _switch_to_window_by_attr(self, attr_name: str, pattern: str) -> bool:
158158
if original is not None:
159159
try:
160160
self.current_webdriver.switch_to.window(original)
161-
except Exception: # noqa: BLE001 — best-effort restore
162-
pass
161+
except Exception as restore_error: # noqa: BLE001 — best-effort restore
162+
web_runner_logger.debug(
163+
f"WebDriverWrapper _switch_to_window_by_attr restore failed: "
164+
f"{repr(restore_error)}"
165+
)
163166
return False
164167

165168
# page / window metadata

0 commit comments

Comments
 (0)