How to use the pyisemail.diagnosis.InvalidDiagnosis 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
github michaelherold / pyIsEmail / pyisemail / validators / parser_validator.py View on Github external
# @
                    elif token == Char.AT:
                        # At this point we should have a valid local-part
                        if len(context_stack) != 1:  # pragma: no cover
                            if diagnose:
                                return InvalidDiagnosis('BAD_PARSE')
                            else:
                                return False

                        if parse_data[Context.LOCALPART] == '':
                            # Fatal error
                            return_status.append(
                                InvalidDiagnosis('NOLOCALPART'))
                        elif element_len == 0:
                            # Fatal error
                            return_status.append(InvalidDiagnosis('DOT_END'))
                        # http://tools.ietf.org/html/rfc5321#section-4.5.3.1.1
                        #   The maximum total length of a user name or other
                        #   local-part is 64 octets.
                        elif len(parse_data[Context.LOCALPART]) > 64:
                            return_status.append(
                                RFC5322Diagnosis('LOCAL_TOOLONG'))
                        # http://tools.ietf.org/html/rfc5322#section-3.4.1
                        #   Comments and folding white space
                        #   SHOULD NOT be used around the "@" in the addr-spec.
                        #
                        # http://tools.ietf.org/html/rfc2119
                        # 4. SHOULD NOT   This phrase, or the phrase "NOT
                        #    RECOMMENDED" mean that there may exist valid
                        #    reasons in particular circumstances when the
                        #    particular behavior is acceptable or even useful,
                        #    but the full implications should be understood and
github michaelherold / pyIsEmail / pyisemail / validators / parser_validator.py View on Github external
#              "!" / "#" /      ; characters not
                        #              "$" / "%" /      ; including specials.
                        #              "&" / "'" /      ; Used for atoms.
                        #              "*" / "+" /
                        #              "-" / "/" /
                        #              "=" / "?" /
                        #              "^" / "_" /
                        #              "`" / "{" /
                        #              "|" / "}" /
                        #              "~"
                        if end_or_die:
                            # We have encountered atext where it is no longer
                            # valid
                            if context_prior in [Context.COMMENT, Context.FWS]:
                                return_status.append(
                                    InvalidDiagnosis('ATEXT_AFTER_CFWS'))
                            elif context_prior == Context.QUOTEDSTRING:
                                return_status.append(
                                    InvalidDiagnosis('ATEXT_AFTER_QS'))
                            else:  # pragma: no cover
                                if diagnose:
                                    return InvalidDiagnosis('BAD_PARSE')
                                else:
                                    return False
                        else:
                            context_prior = context
                            o = ord(token)

                            if (o < 33 or o > 126 or o == 10 or
                                    token in Char.SPECIALS):
                                return_status.append(
                                    InvalidDiagnosis('EXPECTING_ATEXT'))
github michaelherold / pyIsEmail / pyisemail / validators / parser_validator.py View on Github external
#
                        #   obs-ctext       =   obs-NO-WS-CTL
                        #
                        #   obs-NO-WS-CTL   =   %d1-8 /      ; US-ASCII control
                        #                       %d11 /       ; characters that
                        #                       %d12 /       ; do not include
                        #                       %d14-31 /    ; the CR, LF, and
                        #                                    ; white space
                        #                                    ; characters

                        o = ord(token)

                        if o > 127 or o == 0 or o == 10:
                            # Fatal error
                            return_status.append(
                                InvalidDiagnosis('EXPECTING_CTEXT'))
                            break
                        elif o < 32 or o == 127:
                            return_status.append(DeprecatedDiagnosis('CTEXT'))

                # -------------------------------------------------------
                # Folding White Space (FWS)
                # -------------------------------------------------------
                elif context == Context.FWS:
                    # http://tools.ietf.org/html/rfc5322#section-3.2.2
                    #   FWS             =   ([*WSP CRLF] 1*WSP) /  obs-FWS
                    #                       ; Folding white space
                    #
                    # But note the erratum:
                    # http://www.rfc-editor.org/errata_search.php?rfc=5322&eid=1908
                    #   In the obsolete syntax, any amount of folding white
                    #   space MAY be inserted where the obs-FWS rule is
github michaelherold / pyIsEmail / pyisemail / validators / parser_validator.py View on Github external
if max(return_status) < BaseDiagnosis.CATEGORIES['RFC5322']:
            if context == Context.QUOTEDSTRING:
                # Fatal error
                return_status.append(InvalidDiagnosis('UNCLOSEDQUOTEDSTR'))
            elif context == Context.QUOTEDPAIR:
                # Fatal error
                return_status.append(InvalidDiagnosis('BACKSLASHEND'))
            elif context == Context.COMMENT:
                # Fatal error
                return_status.append(InvalidDiagnosis('UNCLOSEDCOMMENT'))
            elif context == Context.LITERAL:
                # Fatal error
                return_status.append(InvalidDiagnosis('UNCLOSEDDOMLIT'))
            elif token == Char.CR:
                # Fatal error
                return_status.append(InvalidDiagnosis('FWS_CRLF_END'))
            elif parse_data[Context.DOMAIN] == '':
                # Fatal error
                return_status.append(InvalidDiagnosis('NODOMAIN'))
            elif element_len == 0:
                # Fatal error
                return_status.append(InvalidDiagnosis('DOT_END'))
            elif hyphen_flag:
                # Fatal error
                return_status.append(InvalidDiagnosis('DOMAINHYPHENEND'))
            # http://tools.ietf.org/html/rfc5321#section-4.5.3.1.2
            # The maximum total length of a domain name or number is 255 octets
            elif len(parse_data[Context.DOMAIN]) > 255:
                return_status.append(RFC5322Diagnosis('DOMAIN_TOOLONG'))
            # http://tools.ietf.org/html/rfc5321#section-4.1.2
            #   Forward-path   = Path
            #
github michaelherold / pyIsEmail / pyisemail / validators / parser_validator.py View on Github external
# http://tools.ietf.org/html/rfc5321#section-4.1.2
                        #   sub-domain     = Let-dig [Ldh-str]
                        #
                        #   Let-dig        = ALPHA / DIGIT
                        #
                        #   Ldh-str        = *( ALPHA / DIGIT / "-" ) Let-dig
                        #
                        if end_or_die:
                            # We have encountered atext where it is no longer
                            # valid
                            if context_prior in [Context.COMMENT, Context.FWS]:
                                return_status.append(
                                    InvalidDiagnosis('ATEXT_AFTER_CFWS'))
                            elif context_prior == Context.LITERAL:
                                return_status.append(
                                    InvalidDiagnosis('ATEXT_AFTER_DOMLIT'))
                            else:  # pragma: no cover
                                if diagnose:
                                    return InvalidDiagnosis('BAD_PARSE')
                                else:
                                    return False

                        o = ord(token)
                        # Assume this token isn't a hyphen unless we discover
                        # it is
                        hyphen_flag = False

                        if o < 33 or o > 126 or token in Char.SPECIALS:
                            # Fatal error
                            return_status.append(
                                InvalidDiagnosis('EXPECTING_ATEXT'))
                        elif token == Char.HYPHEN:
github michaelherold / pyIsEmail / pyisemail / validators / parser_validator.py View on Github external
break

        # Some simple final tests
        if max(return_status) < BaseDiagnosis.CATEGORIES['RFC5322']:
            if context == Context.QUOTEDSTRING:
                # Fatal error
                return_status.append(InvalidDiagnosis('UNCLOSEDQUOTEDSTR'))
            elif context == Context.QUOTEDPAIR:
                # Fatal error
                return_status.append(InvalidDiagnosis('BACKSLASHEND'))
            elif context == Context.COMMENT:
                # Fatal error
                return_status.append(InvalidDiagnosis('UNCLOSEDCOMMENT'))
            elif context == Context.LITERAL:
                # Fatal error
                return_status.append(InvalidDiagnosis('UNCLOSEDDOMLIT'))
            elif token == Char.CR:
                # Fatal error
                return_status.append(InvalidDiagnosis('FWS_CRLF_END'))
            elif parse_data[Context.DOMAIN] == '':
                # Fatal error
                return_status.append(InvalidDiagnosis('NODOMAIN'))
            elif element_len == 0:
                # Fatal error
                return_status.append(InvalidDiagnosis('DOT_END'))
            elif hyphen_flag:
                # Fatal error
                return_status.append(InvalidDiagnosis('DOMAINHYPHENEND'))
            # http://tools.ietf.org/html/rfc5321#section-4.5.3.1.2
            # The maximum total length of a domain name or number is 255 octets
            elif len(parse_data[Context.DOMAIN]) > 255:
                return_status.append(RFC5322Diagnosis('DOMAIN_TOOLONG'))
github michaelherold / pyIsEmail / pyisemail / validators / parser_validator.py View on Github external
# No point in going on if we've got a fatal error
            if max(return_status) > BaseDiagnosis.CATEGORIES['RFC5322']:
                break

        # Some simple final tests
        if max(return_status) < BaseDiagnosis.CATEGORIES['RFC5322']:
            if context == Context.QUOTEDSTRING:
                # Fatal error
                return_status.append(InvalidDiagnosis('UNCLOSEDQUOTEDSTR'))
            elif context == Context.QUOTEDPAIR:
                # Fatal error
                return_status.append(InvalidDiagnosis('BACKSLASHEND'))
            elif context == Context.COMMENT:
                # Fatal error
                return_status.append(InvalidDiagnosis('UNCLOSEDCOMMENT'))
            elif context == Context.LITERAL:
                # Fatal error
                return_status.append(InvalidDiagnosis('UNCLOSEDDOMLIT'))
            elif token == Char.CR:
                # Fatal error
                return_status.append(InvalidDiagnosis('FWS_CRLF_END'))
            elif parse_data[Context.DOMAIN] == '':
                # Fatal error
                return_status.append(InvalidDiagnosis('NODOMAIN'))
            elif element_len == 0:
                # Fatal error
                return_status.append(InvalidDiagnosis('DOT_END'))
            elif hyphen_flag:
                # Fatal error
                return_status.append(InvalidDiagnosis('DOMAINHYPHENEND'))
            # http://tools.ietf.org/html/rfc5321#section-4.5.3.1.2
github michaelherold / pyIsEmail / pyisemail / validators / parser_validator.py View on Github external
#   Let-dig        = ALPHA / DIGIT
                        #
                        #   Ldh-str        = *( ALPHA / DIGIT / "-" ) Let-dig
                        #
                        if end_or_die:
                            # We have encountered atext where it is no longer
                            # valid
                            if context_prior in [Context.COMMENT, Context.FWS]:
                                return_status.append(
                                    InvalidDiagnosis('ATEXT_AFTER_CFWS'))
                            elif context_prior == Context.LITERAL:
                                return_status.append(
                                    InvalidDiagnosis('ATEXT_AFTER_DOMLIT'))
                            else:  # pragma: no cover
                                if diagnose:
                                    return InvalidDiagnosis('BAD_PARSE')
                                else:
                                    return False

                        o = ord(token)
                        # Assume this token isn't a hyphen unless we discover
                        # it is
                        hyphen_flag = False

                        if o < 33 or o > 126 or token in Char.SPECIALS:
                            # Fatal error
                            return_status.append(
                                InvalidDiagnosis('EXPECTING_ATEXT'))
                        elif token == Char.HYPHEN:
                            if element_len == 0:
                                # Hyphens can't be at the beginning of a
                                # subdomain