Skip to content

Commit d0f1852

Browse files
committed
more updates
1 parent 283893a commit d0f1852

File tree

10 files changed

+49
-46
lines changed

10 files changed

+49
-46
lines changed

nodescraper/base/inbandcollectortask.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
#
2525
###############################################################################
2626
import logging
27-
from typing import Generic, Optional
27+
from typing import Generic, Optional, Union
2828

2929
from nodescraper.connection.inband import InBandConnection
3030
from nodescraper.connection.inband.inband import BaseFileArtifact, CommandArtifact
@@ -49,7 +49,7 @@ def __init__(
4949
connection: InBandConnection,
5050
logger: Optional[logging.Logger] = None,
5151
system_interaction_level: SystemInteractionLevel = SystemInteractionLevel.INTERACTIVE,
52-
max_event_priority_level: EventPriority | str = EventPriority.CRITICAL,
52+
max_event_priority_level: Union[EventPriority, str] = EventPriority.CRITICAL,
5353
parent: Optional[str] = None,
5454
task_result_hooks: Optional[list[TaskResultHook]] = None,
5555
**kwargs,

nodescraper/base/regexanalyzer.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#
2525
###############################################################################
2626
import re
27+
from typing import Union
2728

2829
from pydantic import BaseModel
2930

@@ -36,7 +37,7 @@
3637
class ErrorRegex(BaseModel):
3738
regex: re.Pattern
3839
message: str
39-
event_category: str | EventCategory = EventCategory.UNKNOWN
40+
event_category: Union[str, EventCategory] = EventCategory.UNKNOWN
4041
event_priority: EventPriority = EventPriority.ERROR
4142

4243

@@ -54,17 +55,18 @@ class RegexAnalyzer(DataAnalyzer[TDataModel, TAnalyzeArg]):
5455
"""Parent class for all regex based data analyzers."""
5556

5657
def _build_regex_event(
57-
self, regex_obj: ErrorRegex, match: str | list[str], source: str
58+
self, regex_obj: ErrorRegex, match: Union[str, list[str]], source: str
5859
) -> RegexEvent:
5960
"""Build a RegexEvent object from a regex match and source.
6061
61-
Args:
62-
regex_obj (ErrorRegex): regex object containing the regex pattern, message, category, and priorit
63-
match (str | list[str]): matched content from the regex
64-
source (str): descriptor for the content where the match was found
62+
Args:
63+
regex_obj (ErrorRegex): regex object containing the regex pattern, message, category, and priorit
64+
match (
65+
Union[str, list[str]]): matched content from the regex
66+
source (str): descriptor for the content where the match was found
6567
66-
Returns:
67-
RegexEvent: an instance of RegexEvent containing the match details
68+
Returns:
69+
RegexEvent: an instance of RegexEvent containing the match details
6870
"""
6971
return RegexEvent(
7072
description=regex_obj.message,

nodescraper/cli/dynamicparserbuilder.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
#
2525
###############################################################################
2626
import argparse
27-
import types
2827
from typing import Optional, Type
2928

3029
from pydantic import BaseModel
@@ -59,7 +58,7 @@ def build_plugin_parser(self) -> dict:
5958
}
6059

6160
# skip args where generic type has been set to None
62-
if types.NoneType in type_class_map:
61+
if type(None) in type_class_map:
6362
continue
6463

6564
model_arg = self.get_model_arg(type_class_map)
@@ -164,7 +163,7 @@ def build_model_arg_parser(self, model: type[BaseModel], required: bool) -> list
164163
type_class.type_class: type_class for type_class in attr_data.type_classes
165164
}
166165

167-
if types.NoneType in type_class_map and len(attr_data.type_classes) == 1:
166+
if type(None) in type_class_map and len(attr_data.type_classes) == 1:
168167
continue
169168

170169
self.add_argument(type_class_map, attr.replace("_", "-"), required)

nodescraper/interfaces/connectionmanager.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
import logging
3030
import types
3131
from functools import wraps
32-
from typing import Callable, Generic, Optional, TypeVar
32+
from typing import Callable, Generic, Optional, TypeVar, Union
3333

3434
from pydantic import BaseModel
3535

@@ -89,9 +89,9 @@ def __init__(
8989
self,
9090
system_info: SystemInfo,
9191
logger: Optional[logging.Logger] = None,
92-
max_event_priority_level: EventPriority | str = EventPriority.CRITICAL,
92+
max_event_priority_level: Union[EventPriority, str] = EventPriority.CRITICAL,
9393
parent: Optional[str] = None,
94-
task_result_hooks: list[TaskResultHook] | types.NoneType = None,
94+
task_result_hooks: Optional[list[TaskResultHook], None] = None,
9595
connection_args: Optional[TConnectArg | dict] = None,
9696
**kwargs,
9797
):

nodescraper/interfaces/datacollectortask.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
import inspect
2828
import logging
2929
from functools import wraps
30-
from typing import Callable, ClassVar, Generic, Optional, Type
30+
from typing import Callable, ClassVar, Generic, Optional, Type, Union
3131

3232
from pydantic import BaseModel, ValidationError
3333

@@ -123,7 +123,7 @@ def __init__(
123123
connection: TConnection,
124124
logger: Optional[logging.Logger] = None,
125125
system_interaction_level: SystemInteractionLevel | str = SystemInteractionLevel.INTERACTIVE,
126-
max_event_priority_level: EventPriority | str = EventPriority.CRITICAL,
126+
max_event_priority_level: Union[EventPriority, str] = EventPriority.CRITICAL,
127127
parent: Optional[str] = None,
128128
task_result_hooks: Optional[list[TaskResultHook]] = None,
129129
**kwargs,

nodescraper/interfaces/dataplugin.py

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
#
2525
###############################################################################
2626
import logging
27-
from typing import Generic, Optional, Type
27+
from typing import Generic, Optional, Type, Union
2828

2929
from nodescraper.enums import EventPriority, ExecutionStatus, SystemInteractionLevel
3030
from nodescraper.generictypes import TAnalyzeArg, TCollectArg, TDataModel
@@ -64,7 +64,7 @@ def __init__(
6464
system_info: SystemInfo,
6565
logger: Optional[logging.Logger] = None,
6666
connection_manager: Optional[TConnectionManager] = None,
67-
connection_args: Optional[TConnectArg | dict] = None,
67+
connection_args: Optional[Union[TConnectArg, dict]] = None,
6868
task_result_hooks: Optional[list[TaskResultHook]] = None,
6969
log_path: Optional[str] = None,
7070
**kwargs,
@@ -127,7 +127,7 @@ def data(self) -> Optional[TDataModel]:
127127
return self._data
128128

129129
@data.setter
130-
def data(self, data: str | dict | TDataModel):
130+
def data(self, data: Optional[str, dict, TDataModel]):
131131
if isinstance(data, (str, dict)):
132132
self._data = self.DATA_MODEL.import_model(data)
133133
elif not isinstance(data, self.DATA_MODEL):
@@ -137,15 +137,17 @@ def data(self, data: str | dict | TDataModel):
137137

138138
def collect(
139139
self,
140-
max_event_priority_level: EventPriority | str = EventPriority.CRITICAL,
141-
system_interaction_level: SystemInteractionLevel | str = SystemInteractionLevel.INTERACTIVE,
140+
max_event_priority_level: Optional[Union[EventPriority, str]] = EventPriority.CRITICAL,
141+
system_interaction_level: Optional[
142+
Union[SystemInteractionLevel, str]
143+
] = SystemInteractionLevel.INTERACTIVE,
142144
preserve_connection: bool = False,
143-
collection_args: Optional[TCollectArg | dict] = None,
145+
collection_args: Optional[Union[TCollectArg, dict]] = None,
144146
) -> TaskResult:
145147
"""Run data collector task
146148
147149
Args:
148-
max_event_priority_level (EventPriority | str, optional): priority limit for events. Defaults to EventPriority.CRITICAL.
150+
max_event_priority_level (Union[EventPriority, str], optional): priority limit for events. Defaults to EventPriority.CRITICAL.
149151
system_interaction_level (SystemInteractionLevel | str, optional): system interaction level. Defaults to SystemInteractionLevel.INTERACTIVE.
150152
preserve_connection (bool, optional): whether we should close the connection after data collection. Defaults to False.
151153
collection_args (Optional[TCollectArg | dict], optional): args for data collection. Defaults to None.
@@ -227,16 +229,16 @@ def collect(
227229

228230
def analyze(
229231
self,
230-
max_event_priority_level: EventPriority | str = EventPriority.CRITICAL,
232+
max_event_priority_level: Optional[Union[EventPriority, str]] = EventPriority.CRITICAL,
231233
analysis_args: Optional[TAnalyzeArg | dict] = None,
232-
data: Optional[str | dict | TDataModel] = None,
234+
data: Optional[Union[str, dict, TDataModel]] = None,
233235
) -> TaskResult:
234236
"""Run data analyzer task
235237
236238
Args:
237-
max_event_priority_level (EventPriority | str, optional): priority limit for events. Defaults to EventPriority.CRITICAL.
239+
max_event_priority_level (Union[EventPriority, str], optional): priority limit for events. Defaults to EventPriority.CRITICAL.
238240
analysis_args (Optional[TAnalyzeArg | dict], optional): args for data analysis. Defaults to None.
239-
data (Optional[str | dict | TDataModel], optional): data to analyze. Defaults to None.
241+
data (Optional[Union[str, dict, TDataModel]], optional): data to analyze. Defaults to None.
240242
241243
Returns:
242244
TaskResult: result of data analysis
@@ -276,10 +278,10 @@ def run(
276278
self,
277279
collection: bool = True,
278280
analysis: bool = True,
279-
max_event_priority_level: EventPriority | str = EventPriority.CRITICAL,
281+
max_event_priority_level: Union[EventPriority, str] = EventPriority.CRITICAL,
280282
system_interaction_level: SystemInteractionLevel | str = SystemInteractionLevel.INTERACTIVE,
281283
preserve_connection: bool = False,
282-
data: Optional[str | dict | TDataModel] = None,
284+
data: Optional[Union[str, dict, TDataModel]] = None,
283285
collection_args: Optional[TCollectArg | dict] = None,
284286
analysis_args: Optional[TAnalyzeArg | dict] = None,
285287
) -> PluginResult:
@@ -288,10 +290,10 @@ def run(
288290
Args:
289291
collection (bool, optional): Enable data collection. Defaults to True.
290292
analysis (bool, optional): Enable data analysis. Defaults to True.
291-
max_event_priority_level (EventPriority | str, optional): Max priority level to assign to events. Defaults to EventPriority.CRITICAL.
293+
max_event_priority_level (Union[EventPriority, str], optional): Max priority level to assign to events. Defaults to EventPriority.CRITICAL.
292294
system_interaction_level (SystemInteractionLevel | str, optional): System interaction level. Defaults to SystemInteractionLevel.INTERACTIVE.
293295
preserve_connection (bool, optional): Whether to close the connection when data collection is complete. Defaults to False.
294-
data (Optional[str | dict | TDataModel], optional): Input data. Defaults to None.
296+
data (Optional[Union[str, dict, TDataModel]], optional): Input data. Defaults to None.
295297
collection_args (Optional[TCollectArg | dict], optional): Arguments for data collection. Defaults to None.
296298
analysis_args (Optional[TAnalyzeArg | dict], optional): Arguments for data analysis. Defaults to None.
297299

nodescraper/interfaces/task.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
import copy
2828
import datetime
2929
import logging
30-
from typing import Any, Optional
30+
from typing import Any, Optional, Union
3131

3232
from nodescraper.constants import DEFAULT_LOGGER
3333
from nodescraper.enums import EventCategory, EventPriority
@@ -51,7 +51,7 @@ def __init__(
5151
self,
5252
system_info: SystemInfo,
5353
logger: Optional[logging.Logger] = None,
54-
max_event_priority_level: EventPriority | str = EventPriority.CRITICAL,
54+
max_event_priority_level: Union[EventPriority, str] = EventPriority.CRITICAL,
5555
parent: Optional[str] = None,
5656
task_result_hooks: Optional[list[TaskResultHook]] = None,
5757
**kwargs: dict[str, Any],
@@ -96,7 +96,7 @@ def __init_subclass__(cls, **kwargs) -> None:
9696

9797
def _build_event(
9898
self,
99-
category: EventCategory | str,
99+
category: Union[EventCategory, str],
100100
description: str,
101101
priority: EventPriority,
102102
data: Optional[dict] = None,
@@ -133,7 +133,7 @@ def _build_event(
133133

134134
def _log_event(
135135
self,
136-
category: EventCategory | str,
136+
category: Union[EventCategory, str],
137137
description: str,
138138
priority: EventPriority,
139139
data: Optional[dict] = None,

nodescraper/models/datamodel.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
import json
2828
import os
2929
import tarfile
30-
from typing import TypeVar
30+
from typing import TypeVar, Union
3131

3232
from pydantic import BaseModel, Field, field_validator
3333

@@ -42,7 +42,7 @@ class FileModel(BaseModel):
4242

4343
@field_validator("file_contents", mode="before")
4444
@classmethod
45-
def file_contents_conformer(cls, value: io.BytesIO | str | bytes) -> bytes:
45+
def file_contents_conformer(cls, value: Union[io.BytesIO, str, bytes]) -> bytes:
4646
if isinstance(value, io.BytesIO):
4747
return value.getvalue()
4848
if isinstance(value, str):
@@ -92,15 +92,15 @@ def merge_data(self, input_data: "DataModel") -> None:
9292
pass
9393

9494
@classmethod
95-
def import_model(cls: type[TDataModel], model_input: dict | str) -> TDataModel:
95+
def import_model(cls: type[TDataModel], model_input: Union[dict, str]) -> TDataModel:
9696
"""import a data model
9797
if the input is a string attempt to read data from file using the string as a file name
9898
if input is a dict, pass key value pairs directly to init function
9999
100100
101101
Args:
102102
cls (type[DataModel]): Data model class
103-
model_input (dict | str): model data input
103+
model_input (Union[dict, str]): model data input
104104
105105
Raises:
106106
ValueError: if model_input has an invalid type

nodescraper/models/event.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
import re
2929
import uuid
3030
from enum import Enum
31-
from typing import Optional
31+
from typing import Optional, Union
3232

3333
from pydantic import BaseModel, Field, field_serializer, field_validator
3434

@@ -80,7 +80,7 @@ def validate_timestamp(cls, timestamp: datetime.datetime) -> datetime.datetime:
8080

8181
@field_validator("category", mode="before")
8282
@classmethod
83-
def validate_category(cls, category: str | Enum) -> str:
83+
def validate_category(cls, category: Optional[Union[str, Enum]]) -> str:
8484
"""ensure category is has consistent formatting
8585
Args:
8686
category (str | Enum): category string
@@ -96,7 +96,7 @@ def validate_category(cls, category: str | Enum) -> str:
9696

9797
@field_validator("priority", mode="before")
9898
@classmethod
99-
def validate_priority(cls, priority: str | EventPriority) -> EventPriority:
99+
def validate_priority(cls, priority: Optional[Union[str, EventPriority]]) -> EventPriority:
100100
"""Allow priority to be set via string priority name
101101
Args:
102102
priority (str | EventPriority): event priority string or enum

nodescraper/models/pluginresult.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
# SOFTWARE.
2424
#
2525
###############################################################################
26-
from typing import Optional
26+
from typing import Optional, Union
2727

2828
from pydantic import BaseModel
2929

@@ -36,4 +36,4 @@ class PluginResult(BaseModel):
3636
status: ExecutionStatus
3737
source: str
3838
message: Optional[str] = None
39-
result_data: Optional[dict | BaseModel] = None
39+
result_data: Optional[Union[dict, BaseModel]] = None

0 commit comments

Comments
 (0)