--- a/iro/validate.py Tue Feb 28 01:18:11 2012 +0100
+++ b/iro/validate.py Tue Feb 28 01:18:52 2012 +0100
@@ -133,22 +133,27 @@
def validate(kwd,func, need=True,*args,**kargs):
'''validate decorator
- use it like this:
- @validate(kwd=userhash, func=vuserhash)
- f(userhash)
- that will validate usrhash with the function vuserhash.
- Every validate function should raise an Exception, if the the value is not valid'''
+use it like this:
+ @validate(kwd=userhash, func=vuserhash)
+ f(userhash)
+that will validate usrhash with the function vuserhash.
+Every validate function should raise an Exception, if the the value is not valid.
+All args and kargs are used to call the validate function.
+if need is True, the kwd can't be None.'''
@decorator
def v(f,*a,**k):
kp=getcallargs(f,*a,**k)
def dfunc(*x,**y):
return None
try:
- if need or kp[kwd] is not None:
+ if kp[kwd] is not None:
dfunc=func
+ elif need:
+ raise ValidateException(field=kwd,msg="%s is nessasary"%kwd)
except KeyError:
if need:
raise ValidateException(field=kwd,msg="%s is nessasary"%kwd)
+ kp[kwd] = None
def _gotResult(value):
kp[kwd] = value