style: ruff format and the lint rules of the driver standard

Mechanical: ruff format, and ruff check --fix with the rule set every NAPALM
driver uses (E, F, I, UP, B at line length 100, Python 3.10). Mapping and
Iterable come from collections.abc, imports are sorted. What ruff cannot
fix comes in the next commit.
This commit is contained in:
Christian Manivong committed 2026-10-23 08:39:45 +02:00
1 parent 5b24675a12
commit 09029ca0a4
29 files changed
+985 -456

No files matched your search

+28 -14
View File
@@ -20,7 +20,8 @@ import ipaddress
import logging
import os
import re
from typing import Any, Mapping
from collections.abc import Mapping
from typing import Any
from urllib.parse import urlsplit
import requests
@@ -80,8 +81,14 @@ class RedfishFeatureLicenseError(RedfishAuthError):
refuses ``Systems/1/Storage`` and ``UpdateService`` for want of DCMS.
"""
def __init__(self, message: str, *, licenses: str = "", status: int | None = None,
path: str | None = None):
def __init__(
self,
message: str,
*,
licenses: str = "",
status: int | None = None,
path: str | None = None,
):
super().__init__(message, status=status, path=path)
#: The licenses the service names, e.g. "DCMS"; empty when it names none.
self.licenses = licenses
@@ -270,8 +277,9 @@ class RedfishTransport:
return "session"
if self.auth == "session":
raise RedfishAuthError(f"{self.base_url}: session login returned no X-Auth-Token")
LOG.info("%s: session login returned no token, falling back to basic auth",
self.base_url)
LOG.info(
"%s: session login returned no token, falling back to basic auth", self.base_url
)
self._call(client.login, auth=AuthMethod.BASIC)
return "basic"
@@ -281,8 +289,9 @@ class RedfishTransport:
except InvalidCredentialsError as exc:
raise RedfishAuthError(f"{self.base_url}: invalid credentials", status=401) from exc
except RedfishPasswordChangeRequiredError as exc:
raise RedfishAuthError(f"{self.base_url}: the account must change its password "
"before it can be used") from exc
raise RedfishAuthError(
f"{self.base_url}: the account must change its password before it can be used"
) from exc
except SessionCreationError as exc:
raise _SessionUnsupported(str(exc).strip()) from exc
except (RetriesExhaustedError, ServerDownOrUnreachableError) as exc:
@@ -300,7 +309,7 @@ class RedfishTransport:
LOG.warning("%s: could not delete the Redfish session: %s", self.base_url, exc)
client._session.close()
def __enter__(self) -> "RedfishTransport":
def __enter__(self) -> RedfishTransport:
self.open()
return self
@@ -340,20 +349,25 @@ class RedfishTransport:
data = resp.dict
except Exception as exc:
if status < 400:
raise RedfishError(f"{method} {path}: response is not JSON",
status=status, path=path) from exc
raise RedfishError(
f"{method} {path}: response is not JSON", status=status, path=path
) from exc
data = {}
if status < 400:
if not isinstance(data, dict):
raise RedfishError(f"{method} {path}: response is not a JSON object",
status=status, path=path)
raise RedfishError(
f"{method} {path}: response is not a JSON object", status=status, path=path
)
return data
detail = _error_message(data)
message = f"{method} {path}: HTTP {status}" + (f": {detail}" if detail else "")
if status == 403 and any(i.endswith(LICENSE_REFUSED) for i in _message_ids(data)):
raise RedfishFeatureLicenseError(
message, licenses=" ".join(" ".join(_message_args(data)).split()),
status=status, path=path)
message,
licenses=" ".join(" ".join(_message_args(data)).split()),
status=status,
path=path,
)
if status in (401, 403):
raise RedfishAuthError(message, status=status, path=path)
if status == 404: