I do not like "dust" and I too would like to avoid having to modify
all validators.
Is there any reason not to strip() all input fields except 'text'
fields by default?
Why would anybody want to have spaces before or after a non-empty
string?

Massimo

On Oct 12, 1:26 pm, devnull <ache...@gmail.com> wrote:
> Thanks Thadeus, that works for me.
>
> An alternative to adding a parameter to individual validators for pre-
> validation steps is to add something optional like [requires] that's
> called [interprets] or something similar -- for a method or a list of
> methods to execute before applying all validators.
>
> One might prefer this if the plan is to trim whitespace before
> applying 3 validators on one field - you'd only say trim once instead
> of repeating it three times. It's less flexible though.
>
> Maybe it's a really bad idea, but there's a chance it might spark a
> better idea.
>
> On Oct 12, 3:59 am, Joe Barnhart <joe.barnh...@gmail.com> wrote:
>
> > +1 on the idea, but the name "dust" seems a little idiomatic, doesn't it?
>
> > As an aside, I discovered the absolutely fastest way to remove a set of
> > characters from text in Python is the string function called "translate".
> > It's wicked fast at removing as well as translating characters.  It's not
> > unicode, tho.
>
> > -- Joe
>
> > On Sat, Oct 10, 2009 at 5:36 PM, Iceberg <iceb...@21cn.com> wrote:
>
> > > On Oct11, 4:21am, Thadeus Burgess <thade...@thadeusb.com> wrote:
>
> > > > > > On Oct 10, 7:52 am, devnull <ache...@gmail.com> wrote:
> > > > > > > Is there an option or a validator that will strip whitespace 
> > > > > > > before
> > > > > > > applying remaining validators for a given field on a form?
>
> > > > > > > Somewhat related: I tried the CLEANUP validator but the resulting
> > > > > > > variable still had characters like !...@#%^ in it. Maybe I
> > > mis-understood
> > > > > > > its purpose... perhaps it strips special characters for the other
> > > > > > > validators, but then when everything is done the original typed
> > > value
> > > > > > > gets sent? It would be cool if there were a validator that took a
> > > > > > > regex or a list of characters and stripped those from the input 
> > > > > > > (so
> > > a
> > > > > > > phone field might ignore everything except digits).
>
> > > > > On Oct 10, 10:02 am, mdipierro <mdipie...@cs.depaul.edu> wrote:
> > > > > I agree. Sometimes I think stripping should be a default for non-text,
> > > > > non-blob fields. Pros/cons?
>
> > > > Breaks backwards compatability. So under our banner of web2pyism, we
> > > can't
> > > > do it.
>
> > > > However, devnull, try this, this will alter the input before you 
> > > > validate
> > > it
> > > > through the form, so you can apply operators, such as stripping, or
> > > > .capitalize() or .upper() or anything really :P
>
> > > > def decode(string, strip="!...@#$%^&*()"):
> > > >    newstr = ""
> > > >    for char in string:
> > > >       if char not in strip:
> > > >          newstr += char
> > > >    return newstr
>
> > > > def myaction():
> > > >    if request.vars:
> > > >       request.vars.fieldname = decode(request.vars.fieldname)
> > > >    form = SQLFORM(db.tablename)
>
> > > >    if form.accepts(request.vars, session):
> > > >       response.flash = "yay"
> > > >    elif form.errors:
> > > >       response.flash = "nay"
> > > >    else:
> > > >       response.flash = "hey"
>
> > > > -Thadeus
>
> > > How about adding a new parameter for some old validators? That will
> > > not break backward compatibility. Here is how.
>
> > > class CLEANUP(Validator):
> > >  def __init__(self,dust=None):
> > >    # dust can be None, or a list of chars (aka string), or a regex.
> > >    # If it is a string, it specifis the set of characters to be
> > > removed.
> > >    # If omitted or None, defaults to removing whitespace.
> > >    # If it is a regex, it removes chars met by the regex.
> > >    self.dust=dust
> > >  def __call__(self,value):
> > >    # the implementation
>
> > > And we can add the new parameter dust for IS_IN_DB too.
>
> > > class IS_IN_DB(Validator):
> > >  def __init__(self, ......, dust=None):
> > >    # mentioned above
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To post to this group, send email to web2py@googlegroups.com
To unsubscribe from this group, send email to 
web2py+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/web2py?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to