From 7719aaa96053ec92caeb4e32e64e5aad6659571c Mon Sep 17 00:00:00 2001 From: Mike Auty Date: Thu, 15 Dec 2016 23:03:48 +0000 Subject: [PATCH] Convert the validity functions to class functions to allow them to be used in __new__ methods. --- volatility/framework/validity.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/volatility/framework/validity.py b/volatility/framework/validity.py index b4314b7d3..6b4eabcf2 100644 --- a/volatility/framework/validity.py +++ b/volatility/framework/validity.py @@ -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