Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.8/site-packages/future/backports/email/errors.py: 83%
41 statements
« prev ^ index » next coverage.py v7.3.1, created at 2023-09-25 06:53 +0000
« prev ^ index » next coverage.py v7.3.1, created at 2023-09-25 06:53 +0000
1# Copyright (C) 2001-2006 Python Software Foundation
2# Author: Barry Warsaw
3# Contact: email-sig@python.org
5"""email package exception classes."""
6from __future__ import unicode_literals
7from __future__ import division
8from __future__ import absolute_import
9from future.builtins import super
12class MessageError(Exception):
13 """Base class for errors in the email package."""
16class MessageParseError(MessageError):
17 """Base class for message parsing errors."""
20class HeaderParseError(MessageParseError):
21 """Error while parsing headers."""
24class BoundaryError(MessageParseError):
25 """Couldn't find terminating boundary."""
28class MultipartConversionError(MessageError, TypeError):
29 """Conversion to a multipart is prohibited."""
32class CharsetError(MessageError):
33 """An illegal charset was given."""
36# These are parsing defects which the parser was able to work around.
37class MessageDefect(ValueError):
38 """Base class for a message defect."""
40 def __init__(self, line=None):
41 if line is not None:
42 super().__init__(line)
43 self.line = line
45class NoBoundaryInMultipartDefect(MessageDefect):
46 """A message claimed to be a multipart but had no boundary parameter."""
48class StartBoundaryNotFoundDefect(MessageDefect):
49 """The claimed start boundary was never found."""
51class CloseBoundaryNotFoundDefect(MessageDefect):
52 """A start boundary was found, but not the corresponding close boundary."""
54class FirstHeaderLineIsContinuationDefect(MessageDefect):
55 """A message had a continuation line as its first header line."""
57class MisplacedEnvelopeHeaderDefect(MessageDefect):
58 """A 'Unix-from' header was found in the middle of a header block."""
60class 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).
63MalformedHeaderDefect = MissingHeaderBodySeparatorDefect
65class MultipartInvariantViolationDefect(MessageDefect):
66 """A message claimed to be a multipart but no subparts were found."""
68class InvalidMultipartContentTransferEncodingDefect(MessageDefect):
69 """An invalid content transfer encoding was set on the multipart itself."""
71class UndecodableBytesDefect(MessageDefect):
72 """Header contained bytes that could not be decoded"""
74class InvalidBase64PaddingDefect(MessageDefect):
75 """base64 encoded sequence had an incorrect length"""
77class InvalidBase64CharactersDefect(MessageDefect):
78 """base64 encoded sequence had characters not in base64 alphabet"""
80# These errors are specific to header parsing.
82class HeaderDefect(MessageDefect):
83 """Base class for a header defect."""
85 def __init__(self, *args, **kw):
86 super().__init__(*args, **kw)
88class InvalidHeaderDefect(HeaderDefect):
89 """Header is not valid, message gives details."""
91class HeaderMissingRequiredValue(HeaderDefect):
92 """A header that must have a value had none"""
94class NonPrintableDefect(HeaderDefect):
95 """ASCII characters outside the ascii-printable range found"""
97 def __init__(self, non_printables):
98 super().__init__(non_printables)
99 self.non_printables = non_printables
101 def __str__(self):
102 return ("the following ASCII non-printables found in header: "
103 "{}".format(self.non_printables))
105class ObsoleteHeaderDefect(HeaderDefect):
106 """Header uses syntax declared obsolete by RFC 5322"""
108class NonASCIILocalPartDefect(HeaderDefect):
109 """local_part contains non-ASCII characters"""
110 # This defect only occurs during unicode parsing, not when
111 # parsing messages decoded from binary.