How to use the pyisemail.diagnosis.DNSDiagnosis function in pyIsEmail

To help you get started, we’ve selected a few pyIsEmail examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github michaelherold / pyIsEmail / tests / validators / __init__.py View on Github external
def _get_diagnosis_class(tag):

    """Get class of the Diagnosis to use for a given tag.

    Keyword arguments:
    tag --- the tag string to look up

    """

    if tag == "ERR":
        d_class = InvalidDiagnosis
    elif tag == "DNSWARN":
        d_class = DNSDiagnosis
    elif tag == "VALID":
        d_class = ValidDiagnosis
    elif tag == "RFC5321":
        d_class = RFC5321Diagnosis
    elif tag == "VALID":
        d_class = ValidDiagnosis
    elif tag == "RFC5321":
        d_class = RFC5321Diagnosis
    elif tag == "RFC5322":
        d_class = RFC5322Diagnosis
    elif tag == "CFWS":
        d_class = CFWSDiagnosis
    elif tag == "DEPREC":
        d_class = DeprecatedDiagnosis
    else:
        d_class = ""
github michaelherold / pyIsEmail / tests / validators / test_dns_validator.py View on Github external
def testWithDiagnosis(self, mocked_method):
        self.assertEqual(
            self.is_valid('example.com', diagnose=True),
            DNSDiagnosis('NO_NAMESERVERS'))
github michaelherold / pyIsEmail / tests / validators / test_dns_validator.py View on Github external
def testWithDiagnosis(self, mocked_method):
        self.assertEqual(
            self.is_valid('example.com', diagnose=True),
            DNSDiagnosis('NO_RECORD'))
github michaelherold / pyIsEmail / tests / validators / test_dns_validator.py View on Github external
def testWithDiagnosis(self, mocked_method):
        self.assertEqual(
            self.is_valid('example.com', diagnose=True),
            DNSDiagnosis('NO_MX_RECORD'))
github michaelherold / pyIsEmail / tests / validators / test_dns_validator.py View on Github external
def testWithDiagnosis(self, mocked_method):
        self.assertEqual(
            self.is_valid('example.com', diagnose=True),
            DNSDiagnosis('DNS_TIMEDOUT'))
github michaelherold / pyIsEmail / pyisemail / validators / dns_validator.py View on Github external
# record.
        try:
            dns.resolver.query(domain, 'MX')
            dns_checked = True
        except (dns.resolver.NXDOMAIN, dns.name.NameTooLong):
            # Domain can't be found in DNS
            return_status.append(DNSDiagnosis('NO_RECORD'))

            # Since dns.resolver gives more information than the PHP analog, we
            # can say that TLDs that throw an NXDOMAIN or NameTooLong error
            # have been checked
            if len(domain.split('.')) == 1:
                dns_checked = True
        except dns.resolver.NoAnswer:
            # MX-record for domain can't be found
            return_status.append(DNSDiagnosis('NO_MX_RECORD'))

            try:
                # TODO: See if we can/need to narrow to A / CNAME
                dns.resolver.query(domain)
            except dns.resolver.NoAnswer:
                # No usable records for the domain can be found
                return_status.append(DNSDiagnosis('NO_RECORD'))
        except dns.resolver.NoNameservers:
            return_status.append(DNSDiagnosis('NO_NAMESERVERS'))
        except (dns.exception.Timeout, dns.resolver.Timeout):
            return_status.append(DNSDiagnosis('DNS_TIMEDOUT'))

        # Check for TLD addresses
        # -----------------------
        # TLD addresses are specifically allowed in RFC 5321 but they are
        # unusual to say the least. We will allocate a separate
github michaelherold / pyIsEmail / pyisemail / validators / dns_validator.py View on Github external
# Since dns.resolver gives more information than the PHP analog, we
            # can say that TLDs that throw an NXDOMAIN or NameTooLong error
            # have been checked
            if len(domain.split('.')) == 1:
                dns_checked = True
        except dns.resolver.NoAnswer:
            # MX-record for domain can't be found
            return_status.append(DNSDiagnosis('NO_MX_RECORD'))

            try:
                # TODO: See if we can/need to narrow to A / CNAME
                dns.resolver.query(domain)
            except dns.resolver.NoAnswer:
                # No usable records for the domain can be found
                return_status.append(DNSDiagnosis('NO_RECORD'))
        except dns.resolver.NoNameservers:
            return_status.append(DNSDiagnosis('NO_NAMESERVERS'))
        except (dns.exception.Timeout, dns.resolver.Timeout):
            return_status.append(DNSDiagnosis('DNS_TIMEDOUT'))

        # Check for TLD addresses
        # -----------------------
        # TLD addresses are specifically allowed in RFC 5321 but they are
        # unusual to say the least. We will allocate a separate
        # status to these addresses on the basis that they are more likely
        # to be typos than genuine addresses (unless we've already
        # established that the domain does have an MX record)
        #
        # http://tools.ietf.org/html/rfc5321#section-2.3.5
        #   In the case of a top-level domain used by itself in an address, a
        #   single string is used without any dots. This makes the requirement,
github michaelherold / pyIsEmail / pyisemail / validators / dns_validator.py View on Github external
# can say that TLDs that throw an NXDOMAIN or NameTooLong error
            # have been checked
            if len(domain.split('.')) == 1:
                dns_checked = True
        except dns.resolver.NoAnswer:
            # MX-record for domain can't be found
            return_status.append(DNSDiagnosis('NO_MX_RECORD'))

            try:
                # TODO: See if we can/need to narrow to A / CNAME
                dns.resolver.query(domain)
            except dns.resolver.NoAnswer:
                # No usable records for the domain can be found
                return_status.append(DNSDiagnosis('NO_RECORD'))
        except dns.resolver.NoNameservers:
            return_status.append(DNSDiagnosis('NO_NAMESERVERS'))
        except (dns.exception.Timeout, dns.resolver.Timeout):
            return_status.append(DNSDiagnosis('DNS_TIMEDOUT'))

        # Check for TLD addresses
        # -----------------------
        # TLD addresses are specifically allowed in RFC 5321 but they are
        # unusual to say the least. We will allocate a separate
        # status to these addresses on the basis that they are more likely
        # to be typos than genuine addresses (unless we've already
        # established that the domain does have an MX record)
        #
        # http://tools.ietf.org/html/rfc5321#section-2.3.5
        #   In the case of a top-level domain used by itself in an address, a
        #   single string is used without any dots. This makes the requirement,
        #   described in more detail below, that only fully-qualified domain
        #   names appear in SMTP transactions on the public Internet,
github michaelherold / pyIsEmail / pyisemail / validators / dns_validator.py View on Github external
if len(domain.split('.')) == 1:
                dns_checked = True
        except dns.resolver.NoAnswer:
            # MX-record for domain can't be found
            return_status.append(DNSDiagnosis('NO_MX_RECORD'))

            try:
                # TODO: See if we can/need to narrow to A / CNAME
                dns.resolver.query(domain)
            except dns.resolver.NoAnswer:
                # No usable records for the domain can be found
                return_status.append(DNSDiagnosis('NO_RECORD'))
        except dns.resolver.NoNameservers:
            return_status.append(DNSDiagnosis('NO_NAMESERVERS'))
        except (dns.exception.Timeout, dns.resolver.Timeout):
            return_status.append(DNSDiagnosis('DNS_TIMEDOUT'))

        # Check for TLD addresses
        # -----------------------
        # TLD addresses are specifically allowed in RFC 5321 but they are
        # unusual to say the least. We will allocate a separate
        # status to these addresses on the basis that they are more likely
        # to be typos than genuine addresses (unless we've already
        # established that the domain does have an MX record)
        #
        # http://tools.ietf.org/html/rfc5321#section-2.3.5
        #   In the case of a top-level domain used by itself in an address, a
        #   single string is used without any dots. This makes the requirement,
        #   described in more detail below, that only fully-qualified domain
        #   names appear in SMTP transactions on the public Internet,
        #   particularly important where top-level domains are involved.
        #