mirror of
https://github.com/volatilityfoundation/volatility3.git
synced 2026-09-06 09:47:38 +02:00
Refactor the validity function names to make it easier for autocomplete to find.
This commit is contained in:
@@ -71,14 +71,14 @@ class ListRequirement(ConfigurationSchemaNode):
|
||||
ConfigurationSchemaNode.__init__(self, *args, **kwargs)
|
||||
if isinstance(element_type, ListRequirement):
|
||||
raise TypeError("ListRequirements cannot contain ListRequirements")
|
||||
self.element_type = self._type_check(element_type, ConfigurationSchemaNode)
|
||||
self.element_type = self._check_type(element_type, ConfigurationSchemaNode)
|
||||
self.min_elements = min_elements
|
||||
self.max_elements = max_elements
|
||||
|
||||
def validate(self, value, context):
|
||||
"""Check the types on each of the returned values and then call the element type's check for each one"""
|
||||
self._type_check(value, list)
|
||||
if not all([self._type_check(element, self.element_type) for element in value]):
|
||||
self._check_type(value, list)
|
||||
if not all([self._check_type(element, self.element_type) for element in value]):
|
||||
raise TypeError("At least one element in the list is not of the correct type.")
|
||||
if not (self.min_elements <= len(value) <= self.max_elements):
|
||||
raise TypeError("List option provided more or less elements than allowed.")
|
||||
|
||||
@@ -14,7 +14,7 @@ class TranslationLayerDependencyResolver(validity.ValidityRoutines):
|
||||
|
||||
def resolve_dependencies(self, configurable):
|
||||
"""Takes a configurable and produces a priority ordered tree of possible solutions to satisfy the various requirements"""
|
||||
self._type_check(configurable, interfaces.configuration.Configurable)
|
||||
self._check_type(configurable, interfaces.configuration.Configurable)
|
||||
|
||||
for requirement in configurable.get_schemas():
|
||||
pass
|
||||
|
||||
@@ -11,8 +11,8 @@ class LayerFactory(validity.ValidityRoutines, list):
|
||||
def __init__(self, name, requirement, lst = None):
|
||||
if lst is None:
|
||||
lst = []
|
||||
self._type_check(lst, list)
|
||||
self._type_check(name, str)
|
||||
self._check_type(lst, list)
|
||||
self._check_type(name, str)
|
||||
self._name = name
|
||||
self._req = requirement
|
||||
|
||||
@@ -26,7 +26,7 @@ class LayerFactory(validity.ValidityRoutines, list):
|
||||
return self._name
|
||||
|
||||
def __setitem__(self, key, value):
|
||||
self._class_check(value, ContextModifierInterface)
|
||||
self._check_class(value, ContextModifierInterface)
|
||||
super(LayerFactory, self).__setitem__(key, value)
|
||||
|
||||
def requirements(self):
|
||||
|
||||
@@ -38,7 +38,7 @@ class ConfigurationSchemaNode(validity.ValidityRoutines):
|
||||
|
||||
def __init__(self, name, description = None, default = None, optional = False):
|
||||
validity.ValidityRoutines.__init__(self)
|
||||
self._type_check(name, str)
|
||||
self._check_type(name, str)
|
||||
if SCHEMA_NAME_DIVIDER in name:
|
||||
raise ValueError("Name cannot contain the namespace divider (" + SCHEMA_NAME_DIVIDER + ")")
|
||||
self._name = name
|
||||
|
||||
@@ -58,7 +58,7 @@ class ContextModifierInterface(validity.ValidityRoutines, metaclass = ABCMeta):
|
||||
:param namespace: Specifies the namespace for all configuration options to be specified under
|
||||
:type namespace: str
|
||||
"""
|
||||
self.namespace = self._type_check(namespace, str)
|
||||
self.namespace = self._check_type(namespace, str)
|
||||
|
||||
def config_get(self, context):
|
||||
return context.config[self.namespace]
|
||||
|
||||
@@ -15,8 +15,8 @@ class DataLayerInterface(validity.ValidityRoutines, configuration.Configurable,
|
||||
"""A Layer that directly holds data (and does not translate it"""
|
||||
|
||||
def __init__(self, context, name):
|
||||
self._type_check(name, str)
|
||||
self._type_check(context, context_module.ContextInterface)
|
||||
self._check_type(name, str)
|
||||
self._check_type(context, context_module.ContextInterface)
|
||||
self._name = name
|
||||
self._context = context
|
||||
|
||||
|
||||
@@ -41,9 +41,9 @@ class ObjectInformation(ReadOnlyMapping):
|
||||
"""Contains information useful/pertinent only to an individual object (like an instance)"""
|
||||
|
||||
def __init__(self, layer_name, offset, member_name = None, parent = None):
|
||||
self._type_check(offset, int)
|
||||
self._check_type(offset, int)
|
||||
if parent:
|
||||
self._type_check(parent, ObjectInterface)
|
||||
self._check_type(parent, ObjectInterface)
|
||||
ReadOnlyMapping.__init__(self, {'layer_name': layer_name,
|
||||
'offset': offset,
|
||||
'member_name': member_name,
|
||||
@@ -57,8 +57,8 @@ class ObjectInterface(validity.ValidityRoutines, metaclass = ABCMeta):
|
||||
# Since objects are likely to be instantiated often,
|
||||
# we're only checking that context, offset and parent
|
||||
# Everything else may be wrong, but that will get caught later on
|
||||
self._type_check(context, context_module.ContextInterface)
|
||||
self._type_check(object_info, ObjectInformation)
|
||||
self._check_type(context, context_module.ContextInterface)
|
||||
self._check_type(object_info, ObjectInformation)
|
||||
|
||||
# Add an empty dictionary at the start to allow objects to add their own data to the vol object
|
||||
#
|
||||
|
||||
@@ -26,7 +26,7 @@ class PluginInterface(validity.ValidityRoutines, interfaces.configuration.Config
|
||||
"""Class that defines the interface all Plugins must maintain"""
|
||||
|
||||
def __init__(self, context):
|
||||
self._type_check(context, interfaces.context.ContextInterface)
|
||||
self._check_type(context, interfaces.context.ContextInterface)
|
||||
self._context = context
|
||||
self.validate_inputs()
|
||||
|
||||
|
||||
@@ -11,9 +11,9 @@ class SymbolTableInterface(validity.ValidityRoutines):
|
||||
"""Handles a table of symbols"""
|
||||
|
||||
def __init__(self, name, native_structures = None):
|
||||
self._type_check(native_structures, NativeTableInterface)
|
||||
self._check_type(native_structures, NativeTableInterface)
|
||||
if name:
|
||||
self._type_check(name, str)
|
||||
self._check_type(name, str)
|
||||
self.name = name or None
|
||||
self._native_structures = native_structures
|
||||
|
||||
@@ -58,7 +58,7 @@ class SymbolTableInterface(validity.ValidityRoutines):
|
||||
|
||||
WARNING: This allows changing the underlying size of all the other structures referenced in the symbolspace
|
||||
"""
|
||||
self._type_check(value, NativeTableInterface)
|
||||
self._check_type(value, NativeTableInterface)
|
||||
self._native_structures = value
|
||||
|
||||
# ## Functions for overriding classes
|
||||
|
||||
@@ -32,7 +32,7 @@ class Memory(validity.ValidityRoutines, collections.abc.Mapping):
|
||||
|
||||
This will throw an exception if the required dependencies are not met
|
||||
"""
|
||||
self._type_check(layer, interfaces.layers.DataLayerInterface)
|
||||
self._check_type(layer, interfaces.layers.DataLayerInterface)
|
||||
if isinstance(layer, interfaces.layers.TranslationLayerInterface):
|
||||
if layer.name in self._layers:
|
||||
raise exceptions.LayerException("Layer " + layer.name + " already exists.")
|
||||
|
||||
@@ -14,7 +14,7 @@ class BufferDataLayer(interfaces.layers.DataLayerInterface):
|
||||
|
||||
def __init__(self, context, name, buffer):
|
||||
interfaces.layers.DataLayerInterface.__init__(self, context, name)
|
||||
self._buffer = self._type_check(buffer, bytes)
|
||||
self._buffer = self._check_type(buffer, bytes)
|
||||
|
||||
@property
|
||||
def maximum_address(self):
|
||||
@@ -39,7 +39,7 @@ class BufferDataLayer(interfaces.layers.DataLayerInterface):
|
||||
|
||||
def write(self, address, data):
|
||||
"""Writes the data from to the buffer"""
|
||||
self._type_check(data, bytes)
|
||||
self._check_type(data, bytes)
|
||||
self._buffer = self._buffer[:address] + data + self._buffer[address + len(data):]
|
||||
|
||||
|
||||
|
||||
@@ -115,7 +115,7 @@ class Pointer(Integer):
|
||||
"""Pointer which points to another object"""
|
||||
|
||||
def __init__(self, context, structure_name, object_info, struct_format, target = None):
|
||||
self._type_check(target, templates.ObjectTemplate)
|
||||
self._check_type(target, templates.ObjectTemplate)
|
||||
Integer.__init__(self,
|
||||
context = context,
|
||||
object_info = object_info,
|
||||
@@ -165,7 +165,7 @@ class BitField(PrimitiveObject, int):
|
||||
"""Object containing a field which is made up of bits rather than whole bytes"""
|
||||
|
||||
def __new__(cls, context, structure_name, object_info, struct_format, target = None, start_bit = 0, end_bit = 0):
|
||||
cls._type_check(target, Integer)
|
||||
cls._check_type(target, Integer)
|
||||
value = target(context = context,
|
||||
structure_name = structure_name,
|
||||
object_info = object_info,
|
||||
@@ -202,12 +202,12 @@ class Array(interfaces.objects.ObjectInterface, collections.Sequence):
|
||||
"""Object which can contain a fixed number of an object type"""
|
||||
|
||||
def __init__(self, context, structure_name, object_info, count = 0, target = None):
|
||||
self._type_check(target, templates.ObjectTemplate)
|
||||
self._check_type(target, templates.ObjectTemplate)
|
||||
interfaces.objects.ObjectInterface.__init__(self,
|
||||
context = context,
|
||||
structure_name = structure_name,
|
||||
object_info = object_info)
|
||||
self._vol['count'] = self._type_check(count, int)
|
||||
self._vol['count'] = self._check_type(count, int)
|
||||
self._vol['target'] = target
|
||||
|
||||
class VolTemplateProxy(interfaces.objects.ObjectInterface.VolTemplateProxy):
|
||||
|
||||
@@ -21,7 +21,7 @@ class ObjectTemplate(interfaces.objects.Template, validity.ValidityRoutines):
|
||||
interfaces.objects.Template.__init__(self,
|
||||
structure_name = structure_name,
|
||||
**arguments)
|
||||
self._class_check(object_class, interfaces.objects.ObjectInterface)
|
||||
self._check_class(object_class, interfaces.objects.ObjectInterface)
|
||||
self.update_vol(object_class = object_class)
|
||||
|
||||
@property
|
||||
|
||||
@@ -8,7 +8,7 @@ Created on 4 May 2013
|
||||
class ValidityRoutines(object):
|
||||
"""Class to hold all validation routines, such as type checking"""
|
||||
|
||||
def _type_check(self, value, valid_type):
|
||||
def _check_type(self, value, valid_type):
|
||||
"""Checks that value is an instance of valid_type, and returns value if it is, or throws a TypeError otherwise
|
||||
|
||||
:param value: The value of which to validate the type
|
||||
@@ -21,7 +21,7 @@ class ValidityRoutines(object):
|
||||
value).__name__
|
||||
return value
|
||||
|
||||
def _class_check(self, klass, valid_class):
|
||||
def _check_class(self, klass, valid_class):
|
||||
"""Checks that class is an instance of valid_class, and returns klass if it is, or throws a TypeError otherwise
|
||||
|
||||
:param klass: Class to validate
|
||||
|
||||
Reference in New Issue
Block a user