[mod_python] using compile_code objects

David Bear David.Bear at asu.edu
Thu Jun 1 00:07:07 EDT 2006


I am thinking of writing a validation code in the definition of a
field that I receive from a web form. For example, if I have a field
named 'state', I would define a dictionary like this:

_states = ['AZ', 'AL', 'MO']
_state = {'name': '',
          'max-length': 2,
	  'validator': 'in n in _states return true'
	  }
then when I read my req.form['state'] I can say something like

if eval(_state['validator']) == true:
  ok

I am wondering a coupling things:

1) has anyone else done something like this?
2) what kind of performance penalty is there for compile and eval
builtins
3) other issues unique to modpython that would make this undesireable
4) how to parameterize a python string that I would compile (so I
could pass in req.form['state'] to the _state['validator'] function.

Hopefully this makes sense.

-- 
David Bear
phone: 	480-965-8257
fax: 	480-965-9189
College of Public Programs/ASU
Wilson Hall 232
Tempe, AZ 85287-0803
 "Beware the IP portfolio, everyone will be suspect of trespassing"


More information about the Mod_python mailing list