def _validate_python(self, value, state):
        if not value:
            raise Invalid(self.message('empty', state), value, state)
        value = value.strip()
        splitted = value.split('@', 1)
        try:
            username, domain = splitted
        except __HOLE__:
            raise Invalid(self.message('noAt', state), value, state)
        if not self.usernameRE.search(username):
            raise Invalid(
                self.message('badUsername', state, username=username),
                value, state)
        try:
            idna_domain = [idna.ToASCII(p) for p in domain.split('.')]
            if six.text_type is str:  # Python 3
                idna_domain = [p.decode('ascii') for p in idna_domain]
            idna_domain = '.'.join(idna_domain)
        except UnicodeError:
            # UnicodeError: label empty or too long
            # This exception might happen if we have an invalid domain name part
            # (for example test@.foo.bar.com)
            raise Invalid(
                self.message('badDomain', state, domain=domain),
                value, state)
        if not self.domainRE.search(idna_domain):
            raise Invalid(
                self.message('badDomain', state, domain=domain),
                value, state)
        if self.resolve_domain:
            assert have_dns, "dnspython should be available"
            global socket
            if socket is None:
                import socket
            try:
                try:
                    dns.resolver.query(domain, 'MX')
                except (dns.resolver.NXDOMAIN, dns.resolver.NoAnswer):
                    try:
                        dns.resolver.query(domain, 'A')
                    except (dns.resolver.NXDOMAIN, dns.resolver.NoAnswer):
                        raise Invalid(
                            self.message('domainDoesNotExist',
                                state, domain=domain), value, state)
            except (socket.error, dns.exception.DNSException) as e:
                raise Invalid(
                    self.message('socketError', state, error=e), value, state)
dataset/ETHPy150Open formencode/formencode/formencode/validators.py/Email._validate_python