On Jan 17, 2006, at 12:48 AM, Karl Guertin wrote:
On 1/16/06, mario ruggier <[EMAIL PROTECTED]> wrote:
At this point I can't help mentioning this really nice generic
validation module, spec.py, that is included in qp [1]. It allows you
to specify data types of arbitrary complexity, with amazing
expressivity, and automates the checking accordingly.
I didn't see any demo code, but it looks like a clever way to declare
validators.
Eh, there is no demo as such. It is however used in several places by
the qp web framework that it is a part of though, so you can browse
around the code for some examples -- the modules qp.lib.session and
qp.lib.user offer abundant examples.
Is it possible to implement something like a password check?
6 chars, < 30 chars, not a dictionary word, at least two of
[a-z][A-Z][0-9][$_^%*#]
Yes of course. You could do this either as a combo of simpler specs, or
as a dedicated spec. There is a length SpecOperator provided, but the
other two would need to be implemented. Once you have those you can say
something like:
password_is = both(length(6,30), <not dict word>, pattern('<regex>'))
To define new SpecOperators, take a look at the base SpecOperator
class, and the many examples already provided, such as: sequence,
mapping, charset, with_attribute, either, both, no, equal, pattern,
subclass, instance, ...
A direct link to the source for this one module, if you prefer, is:
<http://www.mems-exchange.org/software/qp/qp-1.3.tar.gz/qp-1.3/lib/
spec.py>
Could the same idea be feasible in js?
Or a whole form check?
FieldsMatch(passwd,passwdverify)
OnlyOneFieldFilledIn(radio_field1, radio_field2, radio_field3,
radio_field4)
spec.py knows nothing about web, forms, etc. A form handling package
can easily use it to do inter-field validation such as what you
mention. (However, the form package that comes with qp does field
validations differently... for several reasons probably, some of them
historic I assume.)
Btw, only one radio field, of same set, can be submitted, guaranteed by
html ;-? But yes, such checks you could also do, but will need to
define teh spec operator class for each of them, or provide a combo of
already existing spec operators.
an_email_is = pattern('[EMAIL PROTECTED],3}$')
I know you were just giving an example, but there are four letter tlds
(.info, .name) so you may want to update this if you're actually using
it and there could be longer. I know there was a push for .mobile, not
sure if that made it.
ya, thanks ;-)
mario