--- 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