Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1114617
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T03:01:54+00:00 2026-05-17T03:01:54+00:00

I wanted to create an IDN-aware formencode validator to use in one of my

  • 0

I wanted to create an IDN-aware formencode validator to use in one of my projects. I used a portion of code from the Django project (http://code.djangoproject.com/svn/django/trunk/django/core/validators.py) to do that, but there must be a trivial error in my code I can’t find :

class Email(formencode.validators.Email):
    def _to_python(self, value, state):
        try:
            return super(Email, self)._to_python(value, state)
        except formencode.Invalid as e:
            # Trivial case failed. Try for possible IDN domain-part

            print 'heywo !'

            if value and u'@' in value:
                parts = value.split(u'@')
                try:
                    parts[-1] = parts[-1].encode('idna')
                except UnicodeError:
                    raise e

                try:
                    super(Email, self)._to_python(u'@'.join(parts), state)
                except formencode.Invalid as ex:
                    raise ex

                return value
            else:
                raise e

When I try to validate an email with an IDN domain (ex: test@wääl.de), the Invalid exception raised by the first call is thrown, and the portion of code after the first except is never executed (‘heywo !’ is never printed).

There is an example :

>>> from test.lib.validators import Email
>>> Email().to_python(u'test@zääz.de')
Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "/usr/local/lib/python2.6/dist-packages/FormEncode-1.2.3dev-py2.6.egg/formencode    /api.py", line 416, in to_python
    vp(value, state)
  File "/usr/local/lib/python2.6/dist-packages/FormEncode-1.2.3dev-py2.6.egg/formencode    /validators.py", line 1352, in validate_python
    value, state)
Invalid: The domain portion of the email address is invalid (the portion after the @: z\xe4\xe4z.de)

What did I do wrong ?

Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T03:01:54+00:00Added an answer on May 17, 2026 at 3:01 am

    Okay, found the answer. I was overloading _to_python instead of validate_python. The class now looks like :

    class Email(formencode.validators.Email):
        def validate_python(self, value, state):
            try:
                super(Email, self).validate_python(value, state)
            except formencode.Invalid as e:
                # Trivial case failed. Try for possible IDN domain-part
                if value and u'@' in value:
                    parts = value.split(u'@')
                    try:
                        parts[-1] = parts[-1].encode('idna')
                    except UnicodeError:
                        raise e
    
                    try:
                        super(Email, self).validate_python(u'@'.join(parts), state)
                    except formencode.Invalid as ex:
                        raise ex
                else:
                    raise e
    

    It’s working perfectly 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I wanted to create smth similar to this one Kansas county map where user
I wanted to create a page with a simple button which runs away from
I wanted to create one js file which includes every js files to attach
I wanted to create an new gesture keyboard which can be used by all
I wanted to create a simple paginated search for my project. I'm having trouble
I wanted to create a function of a certain type. I've found one way
I wanted to create a string padding function for the use of left-padding a
i wanted to create a forloop which will create a table from the data
I wanted to create a generic interface with a method I could use to
I wanted to create a three dimensional array in the following code but i

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.