11__author__ = "desultory"
2- __version__ = "1.2.1 "
2+ __version__ = "1.2.2 "
33
44
55from functools import wraps
99def check_dict (key , validate_dict = None , value = None , value_arg = None ,
1010 contains = False , unset = False , not_empty = False ,
1111 raise_exception = False , return_val = False , return_arg = None ,
12- log_level = 10 , _log_bump = 0 , message = None ):
12+ log_level = 10 , debug_level = 5 , message = None ):
1313 """
1414 Adds a check for a dict key to a function.
1515 If the dict is not passed, uses the first argument of the function (often self).
@@ -27,13 +27,12 @@ def validation_wrapper(*args, **kwargs):
2727
2828 check_val = args [value_arg ] if value_arg is not None else value
2929 if hasattr (args [0 ], "logger" ):
30- lvl = max (10 - _log_bump , 0 )
31- args [0 ].logger .log (lvl , "[%s] Checking dict key: %s" % (func .__name__ , key ))
30+ args [0 ].logger .log (debug_level , "[%s] Checking dict key: %s" % (func .__name__ , key ))
3231 if isinstance (validate_dict , dict ):
33- args [0 ].logger .log (lvl , "[%s] Dict:\n %s" % (func .__name__ , validate_dict ))
32+ args [0 ].logger .log (debug_level , "[%s] Dict:\n %s" % (func .__name__ , validate_dict ))
3433 else :
35- args [0 ].logger .log (lvl , "[%s] Data: %s" % (func .__name__ , validate_dict ))
36- args [0 ].logger .log (lvl , "[%s] Checking for value: %s" % (func .__name__ , check_val ))
34+ args [0 ].logger .log (debug_level , "[%s] Data: %s" % (func .__name__ , validate_dict ))
35+ args [0 ].logger .log (debug_level , "[%s] Checking for value: %s" % (func .__name__ , check_val ))
3736
3837 if not validate_dict :
3938 raise ValueError ("validate_dict must be specified." )
@@ -89,7 +88,7 @@ def dispatch_msg(msg):
8988 return dispatch_msg ("[%s] Key: %s has value: %s, but expected: %s." % (func .__name__ , key , dict_val , check_val ))
9089
9190 if hasattr (args [0 ], "logger" ):
92- args [0 ].logger .debug ( "[%s] Validation successful for key: %s." % (func .__name__ , key ))
91+ args [0 ].logger .log ( debug_level , "[%s] Validation successful for key: %s." % (func .__name__ , key ))
9392
9493 return func (* args , ** kwargs )
9594 return validation_wrapper
0 commit comments