Re: Validation as WSGI middleware: good or bad idea?

Ian Bicking <[email protected]> Mon, 01 Dec 2008 13:53:47 -0600
Newsgroups gmane.comp.python.formencode
Message-ID <[email protected]>
Matthew Wilson wrote:
> Maybe it is because I am just beginning to understand how to use WSGI
> middleware, but I have been daydreaming about moving validation into
> the middleware layer, rather than something that happens further
> downstream.
> 
> This might be useful if I want to hop to a completely different block
> of code when validation fails.  It might make really common validators
> less obtrusive.
> 
> All comments are welcome -- am looking for feedback.

I think this is possible, but could easily turn into something too 
complex and hard to modify.  You'd have to wrap the middleware around 
very specific WSGI apps (i.e., and app that just displays one form -- 
which might describe something like a single Pylons Controller) and then 
handle all the possible errors from within the FormEncode validators. 
SimpleFormValidator might make this somewhat clearer, but I'd still 
expect this to be challenging.

Interestingly, though, you could do things like add validation to static 
HTML forms, PHP apps, etc.

-- 
Ian Bicking : [email protected] : http://blog.ianbicking.org

-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/