Re: Why does Email(not_empty=True) accept empty values?
Gustavo Narea <me-essWiSEiJ2uHaexy/[email protected]> Mon, 11 Aug 2008 21:11:20 +0200
| Newsgroups | gmane.comp.python.formencode |
|---|---|
| Message-ID | <[email protected]> |
Hello, Ian.
Whoa, this is what I call a prompt answer ;)
Thank you very much, now I understand. Now it works if the parent constructor
is called with not_empty=True.
Cheers.
On Monday 11 August 2008 21:05:00 you wrote:
> Gustavo Narea wrote:
> > Hello, everyone.
> >
> > I don't understand why I get this:
> >>>>> validator = EmailValidator()
> >>>>> print validator.to_python('')
> >>
> >> None
> >
> > being EmailValidator defined as:
> > ====-start-=====
> > class EmailValidator(FancyValidator):
> >
> > def __init__(self, not_empty=True, resolve_domain=False, max=255,
> > **kwargs):
> > super(EmailValidator, self).__init__(**kwargs)
> > self.length_validator = MaxLength(max)
> > self.email_validator = Email(not_empty=not_empty, strip=True,
> > resolve_domain=resolve_domain)
> >
> > def validate_python(self, value, state):
> > try:
> > self.length_validator.to_python(value, state)
> > return self.email_validator.to_python(value, state)
> > except Invalid, msg:
> > raise InvalidEmailError(msg, value, state)
> > =====-end-=====
> >
> > Shouldn't validate_python() raise an exception if it receives an empty
> > string?
> >
> > Thanks in advance.
>
> All validators (at least the ones that subclass FancyValidator) accept
> empty unless you say not_empty=True -- the standard validate_python
> routing isn't even called in the case of an empty value.
>
> They used to actually be a mix, where some would accept empty and others
> would not, but this caused confusion for a lot of people.
--
Gustavo Narea.
http://gustavonarea.net/
Get rid of unethical constraints! Switch to Freedomware:
http://softwareliberty.com/
-------------------------------------------------------------------------
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=/