mirror of
https://github.com/volatilityfoundation/volatility3.git
synced 2026-08-25 23:52:23 +02:00
Tidy up the requirements namespace.
This commit is contained in:
@@ -10,7 +10,6 @@ import typing
|
||||
|
||||
from volatility.framework import interfaces, constants
|
||||
from volatility.framework.interfaces import configuration as interfaces_configuration
|
||||
from volatility.framework.interfaces.configuration import RequirementInterface, InstanceRequirement, vollog, path_join
|
||||
|
||||
vollog = logging.getLogger(__name__)
|
||||
|
||||
@@ -53,7 +52,7 @@ class BytesRequirement(interfaces_configuration.InstanceRequirement):
|
||||
instance_type = bytes # type: typing.ClassVar[typing.Type]
|
||||
|
||||
|
||||
class ListRequirement(RequirementInterface):
|
||||
class ListRequirement(interfaces_configuration.RequirementInterface):
|
||||
"""Allows for a list of a specific type of requirement (all of which must be met for this requirement to be met) to be specified
|
||||
|
||||
This roughly correlates to allowing a number of arguments to follow a command line parameter,
|
||||
@@ -64,20 +63,20 @@ class ListRequirement(RequirementInterface):
|
||||
"""
|
||||
|
||||
def __init__(self,
|
||||
element_type: InstanceRequirement,
|
||||
element_type: interfaces_configuration.InstanceRequirement,
|
||||
max_elements: int,
|
||||
min_elements: int, *args, **kwargs) -> None:
|
||||
"""Constructs the object
|
||||
|
||||
:param element_type: The (requirement) type of each element within the list
|
||||
:type element_type: InstanceRequirement
|
||||
:type element_type: interfaces_configuration.InstanceRequirement
|
||||
:param max_elements; The maximum number of acceptable elements this list can contain
|
||||
:type max_elements: int
|
||||
:param min_elements: The minimum number of acceptable elements this list can contain
|
||||
:type min_elements: int
|
||||
"""
|
||||
super().__init__(*args, **kwargs)
|
||||
if not isinstance(element_type, InstanceRequirement):
|
||||
if not isinstance(element_type, interfaces_configuration.InstanceRequirement):
|
||||
raise TypeError("ListRequirements can only contain simple InstanceRequirements")
|
||||
self.element_type = element_type
|
||||
self.min_elements = min_elements # type: int
|
||||
@@ -91,10 +90,10 @@ class ListRequirement(RequirementInterface):
|
||||
raise ValueError("")
|
||||
if not (self.min_elements <= len(value) <= self.max_elements):
|
||||
vollog.log(constants.LOGLEVEL_V, "TypeError - List option provided more or less elements than allowed.")
|
||||
return [path_join(config_path, self.name)]
|
||||
return [interfaces_configuration.path_join(config_path, self.name)]
|
||||
if not all([self._check_type(element, self.element_type.instance_type) for element in value]):
|
||||
vollog.log(constants.LOGLEVEL_V, "TypeError - At least one element in the list is not of the correct type.")
|
||||
return [path_join(config_path, self.name)]
|
||||
return [interfaces_configuration.path_join(config_path, self.name)]
|
||||
result = []
|
||||
for element in value:
|
||||
if isinstance(element, str):
|
||||
@@ -104,7 +103,7 @@ class ListRequirement(RequirementInterface):
|
||||
return result
|
||||
|
||||
|
||||
class ChoiceRequirement(RequirementInterface):
|
||||
class ChoiceRequirement(interfaces_configuration.RequirementInterface):
|
||||
"""Allows one from a choice of strings"""
|
||||
|
||||
def __init__(self, choices: typing.List[str], *args, **kwargs) -> None:
|
||||
@@ -123,5 +122,5 @@ class ChoiceRequirement(RequirementInterface):
|
||||
value = self.config_value(context, config_path)
|
||||
if value not in self.choices:
|
||||
vollog.log(constants.LOGLEVEL_V, "ValueError - Value is not within the set of available choices")
|
||||
return [path_join(config_path, self.name)]
|
||||
return [interfaces_configuration.path_join(config_path, self.name)]
|
||||
return []
|
||||
|
||||
Reference in New Issue
Block a user