Add in initial work at interface type-annotations.

This commit is contained in:
Mike Auty
2017-12-13 20:48:52 +00:00
parent 2cc456e847
commit 5536412a5e
2 changed files with 24 additions and 10 deletions
+14 -4
View File
@@ -5,7 +5,7 @@ Automagic objects attempt to automatically fill configuration values that a user
import typing
from abc import ABCMeta, abstractmethod
from volatility.framework import validity
from volatility.framework import validity, interfaces
from volatility.framework.interfaces import configuration as interfaces_configuration
@@ -33,7 +33,9 @@ class AutomagicInterface(interfaces_configuration.ConfigurableInterface, metacla
priority = 10
"""An ordering to indicate how soon this automagic should be run"""
def __init__(self, context, config_path, *args, **kwargs):
def __init__(self,
context: interfaces.context.ContextInterface,
config_path: str, *args, **kwargs) -> None:
super().__init__(context, config_path)
for requirement in self.get_requirements():
if not isinstance(requirement, (interfaces_configuration.InstanceRequirement,
@@ -43,7 +45,11 @@ class AutomagicInterface(interfaces_configuration.ConfigurableInterface, metacla
"Automagic requirements must be an InstanceRequirement, ChoiceRequirement or ListRequirement")
@abstractmethod
def __call__(self, context, config_path, configurable, progress_callback = None):
def __call__(self,
context: interfaces.context.ContextInterface,
config_path: str,
configurable: interfaces.configuration.ConfigurableInterface,
progress_callback: validity.ProgressCallback = None) -> typing.List[str]:
"""Runs the automagic over the configurable"""
def find_requirements(self, context, config_path, requirement_root, requirement_type, shortcut = True) \
@@ -85,7 +91,11 @@ class StackerLayerInterface(validity.ValidityRoutines, metaclass = ABCMeta):
@classmethod
@abstractmethod
def stack(self, context, layer_name, progress_callback = None):
def stack(self,
context: interfaces.context.ContextInterface,
layer_name: str,
progress_callback: validity.ProgressCallback = None) \
-> typing.Optional[interfaces.layers.DataLayerInterface]:
"""Method to determine whether this builder can operate on the named layer,
If so, modify the context appropriately.
@@ -18,7 +18,7 @@ import sys
import typing
from abc import ABCMeta, abstractmethod
from volatility.framework import constants
from volatility.framework import constants, interfaces
from volatility.framework import validity
from volatility.framework.interfaces.context import ContextInterface
@@ -269,21 +269,23 @@ class RequirementInterface(validity.ValidityRoutines, metaclass = ABCMeta):
# Child operations
@property
def requirements(self):
def requirements(self) -> typing.Dict[str, 'RequirementInterface']:
"""Returns a dictionary of all the child requirements, indexed by name"""
return self._requirements.copy()
def add_requirement(self, requirement):
def add_requirement(self, requirement: 'RequirementInterface') -> None:
"""Adds a child to the list of requirements"""
self._check_type(requirement, RequirementInterface)
self._requirements[requirement.name] = requirement
def remove_requirement(self, requirement):
def remove_requirement(self, requirement: 'RequirementInterface') -> None:
"""Removes a child from the list of requirements"""
self._check_type(requirement, RequirementInterface)
del self._requirements[requirement.name]
def unsatisfied_children(self, context, config_path):
def unsatisfied_children(self,
context: interfaces.context.ContextInterface,
config_path: str) -> typing.List[str]:
"""Method that will validate all child requirements"""
result = []
for requirement in self.requirements.values():
@@ -295,7 +297,9 @@ class RequirementInterface(validity.ValidityRoutines, metaclass = ABCMeta):
# Validation routines
@abstractmethod
def unsatisfied(self, context, config_path):
def unsatisfied(self,
context: interfaces.context.ContextInterface,
config_path: str) -> typing.List[str]:
"""Method to validate the value stored at config_path for the configuration object against a context
Returns a list containing its own name (or multiple unsatisfied requirement names) when invalid