# HG changeset patch # User Sandro Knauß # Date 1335305187 -7200 # Node ID 4841b443f1fda0422153db90eb42c62f60cb9841 # Parent 88d45c846f2b84250ff7837cc67559fa41cea7ff validate: adding vInteger diff -r 88d45c846f2b -r 4841b443f1fd iro/validate.py --- a/iro/validate.py Wed Apr 25 00:05:53 2012 +0200 +++ b/iro/validate.py Wed Apr 25 00:06:27 2012 +0200 @@ -23,12 +23,12 @@ else: raise ValidateException(field=field, msg='%s is not boolean' % field) - -def vInteger(value, field, minv=None, maxv=None, none_allowed=False): +def vNumber(value,field, nval, minv=None, maxv=None, none_allowed=False): """validate function for integer values. :param integer minv: minimum value :param integer maxv: maximum value + :param func nval: function that give back a number :param boolean none_allowed: is None or empty string allowed :return: **value** :raises: :exc:`iro.error.ValidateException` @@ -37,7 +37,7 @@ return None try: - ret = int(value) + ret = nval(value) except ValueError: raise ValidateException(field=field) except TypeError: @@ -51,6 +51,34 @@ return ret +def vInteger(value, field, minv=None, maxv=None, none_allowed=False): + """validate function for integer values. + + :param integer minv: minimum value + :param integer maxv: maximum value + :param boolean none_allowed: is None or empty string allowed + :return: **value** + :raises: :exc:`iro.error.ValidateException` + + see also :func:vNumber + """ + return vNumber(value, field, int, minv, maxv, none_allowed) + +def vFloat(value, field, minv=None, maxv=None, none_allowed=False): + """validate function for float values. + + :param integer minv: minimum value + :param integer maxv: maximum value + :param boolean none_allowed: is None or empty string allowed + :return: **value** + :raises: :exc:`iro.error.ValidateException` + + see also :func:vNumber + """ + return vNumber(value, field, float, minv, maxv, none_allowed) + + + def vHash(value,field,minlength=None,maxlength=None): '''Validate function for hash values