| 1 | n/a | # Copyright (C) 2001-2006 Python Software Foundation |
|---|
| 2 | n/a | # Author: Barry Warsaw |
|---|
| 3 | n/a | # Contact: email-sig@python.org |
|---|
| 4 | n/a | |
|---|
| 5 | n/a | """email package exception classes.""" |
|---|
| 6 | n/a | |
|---|
| 7 | n/a | |
|---|
| 8 | n/a | class MessageError(Exception): |
|---|
| 9 | n/a | """Base class for errors in the email package.""" |
|---|
| 10 | n/a | |
|---|
| 11 | n/a | |
|---|
| 12 | n/a | class MessageParseError(MessageError): |
|---|
| 13 | n/a | """Base class for message parsing errors.""" |
|---|
| 14 | n/a | |
|---|
| 15 | n/a | |
|---|
| 16 | n/a | class HeaderParseError(MessageParseError): |
|---|
| 17 | n/a | """Error while parsing headers.""" |
|---|
| 18 | n/a | |
|---|
| 19 | n/a | |
|---|
| 20 | n/a | class BoundaryError(MessageParseError): |
|---|
| 21 | n/a | """Couldn't find terminating boundary.""" |
|---|
| 22 | n/a | |
|---|
| 23 | n/a | |
|---|
| 24 | n/a | class MultipartConversionError(MessageError, TypeError): |
|---|
| 25 | n/a | """Conversion to a multipart is prohibited.""" |
|---|
| 26 | n/a | |
|---|
| 27 | n/a | |
|---|
| 28 | n/a | class CharsetError(MessageError): |
|---|
| 29 | n/a | """An illegal charset was given.""" |
|---|
| 30 | n/a | |
|---|
| 31 | n/a | |
|---|
| 32 | n/a | # These are parsing defects which the parser was able to work around. |
|---|
| 33 | n/a | class MessageDefect(ValueError): |
|---|
| 34 | n/a | """Base class for a message defect.""" |
|---|
| 35 | n/a | |
|---|
| 36 | n/a | def __init__(self, line=None): |
|---|
| 37 | n/a | if line is not None: |
|---|
| 38 | n/a | super().__init__(line) |
|---|
| 39 | n/a | self.line = line |
|---|
| 40 | n/a | |
|---|
| 41 | n/a | class NoBoundaryInMultipartDefect(MessageDefect): |
|---|
| 42 | n/a | """A message claimed to be a multipart but had no boundary parameter.""" |
|---|
| 43 | n/a | |
|---|
| 44 | n/a | class StartBoundaryNotFoundDefect(MessageDefect): |
|---|
| 45 | n/a | """The claimed start boundary was never found.""" |
|---|
| 46 | n/a | |
|---|
| 47 | n/a | class CloseBoundaryNotFoundDefect(MessageDefect): |
|---|
| 48 | n/a | """A start boundary was found, but not the corresponding close boundary.""" |
|---|
| 49 | n/a | |
|---|
| 50 | n/a | class FirstHeaderLineIsContinuationDefect(MessageDefect): |
|---|
| 51 | n/a | """A message had a continuation line as its first header line.""" |
|---|
| 52 | n/a | |
|---|
| 53 | n/a | class MisplacedEnvelopeHeaderDefect(MessageDefect): |
|---|
| 54 | n/a | """A 'Unix-from' header was found in the middle of a header block.""" |
|---|
| 55 | n/a | |
|---|
| 56 | n/a | class MissingHeaderBodySeparatorDefect(MessageDefect): |
|---|
| 57 | n/a | """Found line with no leading whitespace and no colon before blank line.""" |
|---|
| 58 | n/a | # XXX: backward compatibility, just in case (it was never emitted). |
|---|
| 59 | n/a | MalformedHeaderDefect = MissingHeaderBodySeparatorDefect |
|---|
| 60 | n/a | |
|---|
| 61 | n/a | class MultipartInvariantViolationDefect(MessageDefect): |
|---|
| 62 | n/a | """A message claimed to be a multipart but no subparts were found.""" |
|---|
| 63 | n/a | |
|---|
| 64 | n/a | class InvalidMultipartContentTransferEncodingDefect(MessageDefect): |
|---|
| 65 | n/a | """An invalid content transfer encoding was set on the multipart itself.""" |
|---|
| 66 | n/a | |
|---|
| 67 | n/a | class UndecodableBytesDefect(MessageDefect): |
|---|
| 68 | n/a | """Header contained bytes that could not be decoded""" |
|---|
| 69 | n/a | |
|---|
| 70 | n/a | class InvalidBase64PaddingDefect(MessageDefect): |
|---|
| 71 | n/a | """base64 encoded sequence had an incorrect length""" |
|---|
| 72 | n/a | |
|---|
| 73 | n/a | class InvalidBase64CharactersDefect(MessageDefect): |
|---|
| 74 | n/a | """base64 encoded sequence had characters not in base64 alphabet""" |
|---|
| 75 | n/a | |
|---|
| 76 | n/a | # These errors are specific to header parsing. |
|---|
| 77 | n/a | |
|---|
| 78 | n/a | class HeaderDefect(MessageDefect): |
|---|
| 79 | n/a | """Base class for a header defect.""" |
|---|
| 80 | n/a | |
|---|
| 81 | n/a | def __init__(self, *args, **kw): |
|---|
| 82 | n/a | super().__init__(*args, **kw) |
|---|
| 83 | n/a | |
|---|
| 84 | n/a | class InvalidHeaderDefect(HeaderDefect): |
|---|
| 85 | n/a | """Header is not valid, message gives details.""" |
|---|
| 86 | n/a | |
|---|
| 87 | n/a | class HeaderMissingRequiredValue(HeaderDefect): |
|---|
| 88 | n/a | """A header that must have a value had none""" |
|---|
| 89 | n/a | |
|---|
| 90 | n/a | class NonPrintableDefect(HeaderDefect): |
|---|
| 91 | n/a | """ASCII characters outside the ascii-printable range found""" |
|---|
| 92 | n/a | |
|---|
| 93 | n/a | def __init__(self, non_printables): |
|---|
| 94 | n/a | super().__init__(non_printables) |
|---|
| 95 | n/a | self.non_printables = non_printables |
|---|
| 96 | n/a | |
|---|
| 97 | n/a | def __str__(self): |
|---|
| 98 | n/a | return ("the following ASCII non-printables found in header: " |
|---|
| 99 | n/a | "{}".format(self.non_printables)) |
|---|
| 100 | n/a | |
|---|
| 101 | n/a | class ObsoleteHeaderDefect(HeaderDefect): |
|---|
| 102 | n/a | """Header uses syntax declared obsolete by RFC 5322""" |
|---|
| 103 | n/a | |
|---|
| 104 | n/a | class NonASCIILocalPartDefect(HeaderDefect): |
|---|
| 105 | n/a | """local_part contains non-ASCII characters""" |
|---|
| 106 | n/a | # This defect only occurs during unicode parsing, not when |
|---|
| 107 | n/a | # parsing messages decoded from binary. |
|---|