diff --git a/mreg_cli/outputmanager.py b/mreg_cli/outputmanager.py index f1259b67..44f43ab7 100644 --- a/mreg_cli/outputmanager.py +++ b/mreg_cli/outputmanager.py @@ -6,6 +6,7 @@ """ import atexit +import datetime import json import os import re @@ -122,7 +123,7 @@ def __new__(cls): return cls._instance def clear(self) -> None: - """Clears the object.""" + """Clear the object.""" self._output: List[str] = [] self._filter_re: Any = None # should be re.Pattern, but python 3.6 doesn't have that self._filter_negate: bool = False @@ -138,7 +139,7 @@ def clear(self) -> None: self._time_started: datetime.datetime = datetime.datetime.now() def recording_clear(self) -> None: - """Clears the recording data.""" + """Clear the recording data.""" self._recorded_data: List[RecordingEntry] = [] self._recording: bool = False self._filename: str = None @@ -233,7 +234,7 @@ def add_ok(self, msg: str) -> None: self._ok.append(msg) def recording_active(self) -> bool: - """Returns True if recording is active.""" + """Return True if recording is active.""" return self._recording def recording_filename(self) -> Optional[str]: @@ -261,6 +262,7 @@ def recording_output(self) -> None: def recording_request( self, method: str, url: str, params: str, data: Dict[str, Any], result: requests.Response ) -> None: + """Record a request, if recording is active.""" if not self.recording_active(): return ret_dict: Dict[str, Any] = { @@ -426,7 +428,7 @@ def filtered_output(self) -> List[str]: return [line for line in lines if filter_re.search(line)] def render(self) -> None: - """Prints the output to stdout, and records it if recording is active.""" + """Print the output to stdout, and records it if recording is active.""" self.recording_output() for line in self.filtered_output(): print(line) diff --git a/mreg_cli/types.py b/mreg_cli/types.py index ba17897c..d1965e7a 100644 --- a/mreg_cli/types.py +++ b/mreg_cli/types.py @@ -1,13 +1,11 @@ """Type definitions for mreg_cli.""" +import ipaddress import sys -from typing import TYPE_CHECKING, Any, Dict, List, Optional +from typing import TYPE_CHECKING, Dict, List, Optional, Union if sys.version_info >= (3, 8): - pass - -if sys.version_info >= (3, 7): - from typing_extensions import TypedDict + from typing import Literal, TypedDict class TimeInfo(TypedDict): """Type definition for time-related information in the recording entry.""" @@ -30,17 +28,16 @@ class RecordingEntry(TypedDict): api_requests: List[str] time: Optional[TimeInfo] + IP_Version = Literal[4, 6] + else: from typing import Any TimeInfo = Dict[str, Any] RecordingEntry = Dict[str, Any] + IP_Version = int -try: - from typing import TypedDict # Python 3.8 and newer -except ImportError: - from typing_extensions import TypedDict # Python 3.6 and 3.7 - +IP_network = Union[ipaddress.IPv4Network, ipaddress.IPv6Network] if TYPE_CHECKING: from typing import Any