annotate CSP2/CSP2_env/env-d9b9114564458d9d-741b3de822f2aaca6c6caa4325c4afce/lib/python3.8/email/errors.py @ 68:5028fdace37b

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