Debian Codegraph @

Lib/email/errors.py

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