mirror of
https://github.com/volatilityfoundation/volatility3.git
synced 2026-08-23 06:42:21 +02:00
Convert the validity functions to class functions to allow them to be used in __new__ methods.
This commit is contained in:
@@ -8,7 +8,8 @@ Created on 4 May 2013
|
||||
class ValidityRoutines(object):
|
||||
"""Class to hold all validation routines, such as type checking"""
|
||||
|
||||
def _check_type(self, value, valid_type):
|
||||
@classmethod
|
||||
def _check_type(cls, 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
|
||||
@@ -17,11 +18,12 @@ class ValidityRoutines(object):
|
||||
:type valid_type: type
|
||||
"""
|
||||
assert isinstance(value,
|
||||
valid_type), self.__class__.__name__ + " expected " + valid_type.__name__ + ", not " + type(
|
||||
valid_type), cls.__name__ + " expected " + valid_type.__name__ + ", not " + type(
|
||||
value).__name__
|
||||
return value
|
||||
|
||||
def _check_class(self, klass, valid_class):
|
||||
@classmethod
|
||||
def _check_class(cls, 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
|
||||
@@ -30,5 +32,5 @@ class ValidityRoutines(object):
|
||||
:type valid_class: class
|
||||
"""
|
||||
assert issubclass(klass,
|
||||
valid_class), self.__class__.__name__ + " expected " + valid_class.__name__ + ", not " + klass.__name__
|
||||
valid_class), cls.__name__ + " expected " + valid_class.__name__ + ", not " + klass.__name__
|
||||
return klass
|
||||
|
||||
Reference in New Issue
Block a user