driver / standard (pull_request) Successful in 16s
driver / lint (pull_request) Successful in 13s
driver / types (pull_request) Successful in 52s
driver / test (3.12) (pull_request) Successful in 55s
driver / test (3.13) (pull_request) Successful in 45s
driver / lowest (pull_request) Successful in 25s
driver / build (pull_request) Successful in 26s
driver / security (pull_request) Successful in 58s
CI / driver (pull_request) Successful in 2m22s
driver / publish (pull_request) Skipped
The checks against line breaks and double quotes made the driver module 27 lines longer than the quality ratchet allows (2014, recorded 1987) and set_interface 53 lines long (limit 50). The checks move to cli_values.py (check_cli_values); the uptime parser, a pure parser without the driver, moves to parsers.py as parse_uptime_seconds and reads its four units in one loop; set_vlan and set_interface say in one docstring line what they refuse. Behaviour is unchanged; the uptime test gains a string without days and an empty one. The baseline is lowered to what is measured now (1971).
28 lines
1.1 KiB
Python
28 lines
1.1 KiB
Python
"""Values the driver writes into a CLI line, checked before anything is sent.
|
|
|
|
A VLAN name goes into ``name "<name>"`` and a port's description into
|
|
``description <text>``, each one line of a block sent line by line in config
|
|
mode. A line break ran the rest as commands of their own; a double quote ended
|
|
the quoted VLAN name (NetOrk/netork#2455).
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import re
|
|
from collections.abc import Mapping
|
|
from typing import Any
|
|
|
|
#: What ends a CLI value early: a line break ends its line, a double quote a quoted value.
|
|
_LINE_BREAK = re.compile(r"[\r\n]")
|
|
_BREAKS_QUOTED_VALUE = re.compile(r'[\r\n"]')
|
|
|
|
|
|
def check_cli_values(config: Mapping[str, Any]) -> None:
|
|
"""Refuse a VLAN name or a description that would break out of its CLI line."""
|
|
name = config.get("name")
|
|
if isinstance(name, str) and _BREAKS_QUOTED_VALUE.search(name):
|
|
raise ValueError(f"VLAN name {name!r} must be one line without double quotes")
|
|
description = config.get("description")
|
|
if isinstance(description, str) and _LINE_BREAK.search(description):
|
|
raise ValueError(f"description {description!r} must be one line")
|