From a2fc59c8aba7237961bf8d67310e9eb47c76b2c0 Mon Sep 17 00:00:00 2001 From: Christian Manivong Date: Fri, 23 Oct 2026 08:52:23 +0200 Subject: [PATCH] fix: what bandit and the remaining lint rules found - get_wan_status: the catch-all except Exception: continue (B112) now logs at debug level before the next WAN service is tried, so a swallowed failure leaves a trace. A module logger is new. - The "any remote host" placeholder of get_nat_translations is a named constant with a nosec (B104): an address reported as data, never a bind. The output is unchanged. - ruff found nothing left after the mechanical pass. --- napalm_fritzbox/fritzbox.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/napalm_fritzbox/fritzbox.py b/napalm_fritzbox/fritzbox.py index fcd6814..d826649 100644 --- a/napalm_fritzbox/fritzbox.py +++ b/napalm_fritzbox/fritzbox.py @@ -32,6 +32,7 @@ management methods (``load_merge_candidate``, ``commit_config``, ...). from __future__ import annotations +import logging import socket from typing import Any @@ -55,6 +56,12 @@ from napalm_device_types.models import ( WirelessClientDict, ) +logger = logging.getLogger(__name__) + +#: The remote host of a NAT translation whose port forward names none: any host. +#: Reported as data, never bound to. +_ANY_REMOTE = "0.0.0.0" # nosec B104 + # Exceptions that indicate an optional/unavailable TR-064 service or action # (e.g. a service not present on a given FritzOS version/model). _OPTIONAL_SERVICE_ERRORS = (FritzServiceError, FritzActionError, FritzConnectionException) @@ -469,6 +476,7 @@ class FritzBoxDriver(ResidentialGatewayDriver): ): continue except Exception: + logger.debug("WAN status from %s: ignored", svc, exc_info=True) continue if wan_service_used: @@ -619,7 +627,7 @@ class FritzBoxDriver(ResidentialGatewayDriver): continue if ":" in forward["internal_ip"]: continue - remote = forward.get("remote_host") or "0.0.0.0" + remote = forward.get("remote_host") or _ANY_REMOTE translations.append( { "protocol": forward["protocol"].lower(),