1- from __future__ import annotations
2-
31import abc
2+ import io
43import time
5- import typing
4+ from typing import Type , TypeVar , final
65
76import pydantic
87import semver
98from pydantic import BaseModel , ConfigDict , field_validator
109
11- if typing .TYPE_CHECKING :
12- import io
10+ from helperFunctions .tag import TagColor
1311
1412
1513class AnalysisFailedError (Exception ):
@@ -31,8 +29,7 @@ class Tag(BaseModel):
3129 #: In FACT_core this is shown as tooltip
3230 value : str
3331 #: The color of the tag
34- #: See :py:class:`helperFunctions.tag.TagColor`.
35- color : str
32+ color : TagColor
3633 #: Whether or not the tag should be shown in parent files.
3734 propagate : bool = False
3835
@@ -54,7 +51,7 @@ class MetaData(BaseModel):
5451 description : str
5552 #: Pydantic model of the object returned by :py:func:`analyse`.
5653 # Note that we cannot allow pydantic dataclasses because they lack the `schema` method
57- Schema : typing . Type
54+ Schema : Type [ BaseModel ]
5855 #: The version of the plugin.
5956 #: It MUST be a `semver <https://semver.org/>`_ version.
6057 #: Here is a quick summary how semver relates to plugins.
@@ -67,13 +64,13 @@ class MetaData(BaseModel):
6764 version : semver .Version
6865 #: The version of the backing analysis system.
6966 #: E.g. for yara plugins this would be the yara version.
70- system_version : typing . Optional [ str ] = None
67+ system_version : str | None = None
7168 #: A list of all plugins that this plugin depends on
72- dependencies : typing . List = pydantic .Field (default_factory = list )
69+ dependencies : list [ str ] = pydantic .Field (default_factory = list )
7370 #: List of mimetypes that should not be processed
74- mime_blacklist : list = pydantic .Field (default_factory = list )
71+ mime_blacklist : list [ str ] = pydantic .Field (default_factory = list )
7572 #: List of mimetypes that should be processed
76- mime_whitelist : list = pydantic .Field (default_factory = list )
73+ mime_whitelist : list [ str ] = pydantic .Field (default_factory = list )
7774 #: The analysis in not expected to take longer than timeout seconds on any given file
7875 #: and will be aborted if the timeout is reached.
7976 timeout : int = 300
@@ -90,7 +87,7 @@ def __init__(self, metadata: MetaData):
9087 self .metadata : AnalysisPluginV0 .MetaData = metadata
9188
9289 # The type MetaData.Schema
93- Schema = typing . TypeVar ('Schema' )
90+ Schema = TypeVar ('Schema' )
9491
9592 def summarize (self , result : Schema ) -> list [str ]: # noqa: ARG002
9693 """
@@ -115,7 +112,7 @@ def analyze(
115112 self ,
116113 file_handle : io .FileIO ,
117114 virtual_file_path : dict ,
118- analyses : dict [str , pydantic . BaseModel ],
115+ analyses : dict [str , BaseModel ],
119116 ) -> Schema :
120117 """Analyze a file.
121118 May return None if nothing was found.
@@ -127,8 +124,8 @@ def analyze(
127124 :return: The analysis if anything was found.
128125 """
129126
130- @typing . final
131- def get_analysis (self , file_handle : io .FileIO , virtual_file_path : dict , analyses : dict [str , dict ]) -> dict :
127+ @final
128+ def get_analysis (self , file_handle : io .FileIO , virtual_file_path : dict , analyses : dict [str , BaseModel ]) -> dict :
132129 start_time = time .time ()
133130 result = self .analyze (file_handle , virtual_file_path , analyses )
134131
0 commit comments