Skip to content

Commit

Permalink
Tidy up the requirements namespace.
Browse files Browse the repository at this point in the history
  • Loading branch information
ikelos committed Feb 10, 2018
1 parent cbe75da commit 4e7fc07
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions volatility/framework/configuration/requirements.py
Expand Up @@ -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__)

Expand Down Expand Up @@ -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,
Expand All @@ -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
Expand All @@ -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):
Expand All @@ -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:
Expand All @@ -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 []

0 comments on commit 4e7fc07

Please sign in to comment.