How to use the pyisemail.diagnosis.ValidDiagnosis 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 create_diagnosis(tag):

    """Create a Diagnosis for a given tag.

    Keyword arguments:
    tag --- the tag string to create a Diagnosis for

    """

    split_tag = tag.split("_")
    d_class = _get_diagnosis_class(split_tag[1])
    diagnosis_type = "_".join(split_tag[2:])
    if diagnosis_type == "" and d_class == ValidDiagnosis:
        diagnosis_type = "VALID"

    return d_class(diagnosis_type)
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),
            ValidDiagnosis())
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 = ""

    return d_class
github michaelherold / pyIsEmail / pyisemail / validators / parser_validator.py View on Github external
# http://tools.ietf.org/html/rfc1035#section-2.3.4
            # labels           63 octets or less
            elif element_len > 63:
                return_status.append(RFC5322Diagnosis('LABEL_TOOLONG'))

        return_status = list(set(return_status))
        final_status = max(return_status)

        if len(return_status) != 1:
            # Remove redundant ValidDiagnosis
            return_status.pop(0)

        parse_data['status'] = return_status

        if final_status < threshold:
            final_status = ValidDiagnosis()

        if diagnose:
            return final_status
        else:
            return final_status < BaseDiagnosis.CATEGORIES['THRESHOLD']
github michaelherold / pyIsEmail / pyisemail / validators / parser_validator.py View on Github external
More specifically, see the follow RFCs:
            * http://tools.ietf.org/html/rfc5321
            * http://tools.ietf.org/html/rfc5322
            * http://tools.ietf.org/html/rfc4291#section-2.2
            * http://tools.ietf.org/html/rfc1123#section-2.1
            * http://tools.ietf.org/html/rfc3696) (guidance only)

        Keyword arguments:
        address    -- address to check.
        diagnose   -- flag to report a diagnosis or a boolean (default False)

        """

        threshold = BaseDiagnosis.CATEGORIES['VALID']
        return_status = [ValidDiagnosis()]
        parse_data = {}

        # Parse the address into components, character by character
        raw_length = len(address)
        context = Context.LOCALPART              # Where we are
        context_stack = [context]                # Where we've been
        context_prior = Context.LOCALPART        # Where we just came from
        token = ''                               # The current character
        token_prior = ''                         # The previous character
        parse_data[Context.LOCALPART] = ''       # The address' components
        parse_data[Context.DOMAIN] = ''
        atom_list = {
            Context.LOCALPART: [''],
            Context.DOMAIN: ['']
        }                                        # The address' dot-atoms
        element_count = 0
github michaelherold / pyIsEmail / pyisemail / grammar.py View on Github external
def parse(self, address, diagnose=False):
        try:
            parsed = self.addr_spec.parseString(address)
            if diagnose:
                return (parsed is not None, ValidDiagnosis())
            else:
                return parsed is not None
        except ParseException as err:
            if diagnose:
                if err.parserElement == "@" or "@" not in err.pstr:
                    diagnosis = InvalidDiagnosis('NODOMAIN')
                else:
                    diagnosis = None
                return (False, diagnosis)
            else:
                return False
github michaelherold / pyIsEmail / pyisemail / validators / dns_validator.py View on Github external
def is_valid(self, domain, diagnose=False):

        """Check whether a domain has a valid MX or A record.

        Keyword arguments:
        domain   --- the domain to check
        diagnose --- flag to report a diagnosis or a boolean (default False)

        """

        return_status = [ValidDiagnosis()]
        dns_checked = False

        # http://tools.ietf.org/html/rfc5321#section-2.3.5
        #   Names that can be resolved to MX RRs or address (i.e., A or AAAA)
        #   RRs (as discussed in Section 5) are permitted, as are CNAME RRs
        #   whose targets can be resolved, in turn, to MX or address RRs.
        #
        # http://tools.ietf.org/html/rfc5321#section-5.1
        #   The lookup first attempts to locate an MX record associated with
        #   the name.  If a CNAME record is found, the resulting name is
        #   processed as if it were the initial name. ... If an empty list of
        #   MXs is returned, the address is treated as if it was associated
        #   with an implicit MX RR, with a preference of 0, pointing to that
        #   host.
        #
        # is_email() author's note: We will regard the existence of a CNAME to