ยปCore Development>Code coverage>Lib/email/errors.py

Python code coverage for Lib/email/errors.py

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