From bcbfee9016805491bb0d06d181eeb6b3eb8c1c1b Mon Sep 17 00:00:00 2001 From: Mike Auty Date: Tue, 29 Dec 2015 22:24:32 +0000 Subject: [PATCH] Refactor the validity function names to make it easier for autocomplete to find. --- volatility/framework/configuration/__init__.py | 6 +++--- volatility/framework/configuration/depresolver.py | 2 +- volatility/framework/contexts/__init__.py | 6 +++--- volatility/framework/interfaces/configuration.py | 2 +- volatility/framework/interfaces/context.py | 2 +- volatility/framework/interfaces/layers.py | 4 ++-- volatility/framework/interfaces/objects.py | 8 ++++---- volatility/framework/interfaces/plugins.py | 2 +- volatility/framework/interfaces/symbols.py | 6 +++--- volatility/framework/layers/__init__.py | 2 +- volatility/framework/layers/physical.py | 4 ++-- volatility/framework/objects/__init__.py | 8 ++++---- volatility/framework/objects/templates.py | 2 +- volatility/framework/validity.py | 4 ++-- 14 files changed, 29 insertions(+), 29 deletions(-) diff --git a/volatility/framework/configuration/__init__.py b/volatility/framework/configuration/__init__.py index dd3e615d2..ceffea5c4 100644 --- a/volatility/framework/configuration/__init__.py +++ b/volatility/framework/configuration/__init__.py @@ -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.") diff --git a/volatility/framework/configuration/depresolver.py b/volatility/framework/configuration/depresolver.py index 4388ece10..39959019a 100644 --- a/volatility/framework/configuration/depresolver.py +++ b/volatility/framework/configuration/depresolver.py @@ -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 diff --git a/volatility/framework/contexts/__init__.py b/volatility/framework/contexts/__init__.py index 8cddfb0f9..e128057cf 100644 --- a/volatility/framework/contexts/__init__.py +++ b/volatility/framework/contexts/__init__.py @@ -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): diff --git a/volatility/framework/interfaces/configuration.py b/volatility/framework/interfaces/configuration.py index 634fbbefd..ec8315cfa 100644 --- a/volatility/framework/interfaces/configuration.py +++ b/volatility/framework/interfaces/configuration.py @@ -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 diff --git a/volatility/framework/interfaces/context.py b/volatility/framework/interfaces/context.py index 9e3c534d0..a5d082859 100644 --- a/volatility/framework/interfaces/context.py +++ b/volatility/framework/interfaces/context.py @@ -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] diff --git a/volatility/framework/interfaces/layers.py b/volatility/framework/interfaces/layers.py index b0168ad23..1eb08d5de 100644 --- a/volatility/framework/interfaces/layers.py +++ b/volatility/framework/interfaces/layers.py @@ -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 diff --git a/volatility/framework/interfaces/objects.py b/volatility/framework/interfaces/objects.py index b902fcd17..0c46af76e 100644 --- a/volatility/framework/interfaces/objects.py +++ b/volatility/framework/interfaces/objects.py @@ -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 # diff --git a/volatility/framework/interfaces/plugins.py b/volatility/framework/interfaces/plugins.py index 13c1656b5..763f5b550 100644 --- a/volatility/framework/interfaces/plugins.py +++ b/volatility/framework/interfaces/plugins.py @@ -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() diff --git a/volatility/framework/interfaces/symbols.py b/volatility/framework/interfaces/symbols.py index 1478c532c..a7fde5c03 100644 --- a/volatility/framework/interfaces/symbols.py +++ b/volatility/framework/interfaces/symbols.py @@ -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 diff --git a/volatility/framework/layers/__init__.py b/volatility/framework/layers/__init__.py index 7c57f5218..887cadae4 100644 --- a/volatility/framework/layers/__init__.py +++ b/volatility/framework/layers/__init__.py @@ -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.") diff --git a/volatility/framework/layers/physical.py b/volatility/framework/layers/physical.py index bae3322d0..bbdbe6a96 100644 --- a/volatility/framework/layers/physical.py +++ b/volatility/framework/layers/physical.py @@ -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):] diff --git a/volatility/framework/objects/__init__.py b/volatility/framework/objects/__init__.py index 1e6bc7eaf..d788be6a4 100644 --- a/volatility/framework/objects/__init__.py +++ b/volatility/framework/objects/__init__.py @@ -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): diff --git a/volatility/framework/objects/templates.py b/volatility/framework/objects/templates.py index 784545100..d90f5779f 100644 --- a/volatility/framework/objects/templates.py +++ b/volatility/framework/objects/templates.py @@ -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 diff --git a/volatility/framework/validity.py b/volatility/framework/validity.py index aa0b63cdf..494d632e0 100644 --- a/volatility/framework/validity.py +++ b/volatility/framework/validity.py @@ -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