From 4e7fc078eebca9a5c1e436ffe00fd440430d36c3 Mon Sep 17 00:00:00 2001 From: Mike Auty Date: Sat, 10 Feb 2018 13:45:17 +0000 Subject: [PATCH] Tidy up the requirements namespace. --- .../framework/configuration/requirements.py | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/volatility/framework/configuration/requirements.py b/volatility/framework/configuration/requirements.py index b7fe6167a..7ce7f793d 100644 --- a/volatility/framework/configuration/requirements.py +++ b/volatility/framework/configuration/requirements.py @@ -10,7 +10,6 @@ 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 @@ def unsatisfied(self, context: interfaces.context.ContextInterface, config_path: 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 @@ def unsatisfied(self, context: interfaces.context.ContextInterface, config_path: 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 @@ def unsatisfied(self, context: interfaces.context.ContextInterface, config_path: 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 []