annotate Lib/email/errors.py @ 87690:66c1c9f32567 default tip

Add use_weakref option to functools.lru_cache The use_weakref option makes lru_cache create weak references to the function arguments when creating the cache key, which prevents them from staying in the memory forever even after all other references to them are gone. This is a proof of concept for http://bugs.python.org/issue19859
author Radomir Dopieralski <devel@sheep.art.pl>
date Tue, 03 Dec 2013 16:02:48 +0100
parents 10a8ad665749
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
43019
d5f3c2f416f2 Copying the email package back, despite its failings.
Guido van Rossum <guido@python.org>
parents:
diff changeset
1 # Copyright (C) 2001-2006 Python Software Foundation
d5f3c2f416f2 Copying the email package back, despite its failings.
Guido van Rossum <guido@python.org>
parents:
diff changeset
2 # Author: Barry Warsaw
d5f3c2f416f2 Copying the email package back, despite its failings.
Guido van Rossum <guido@python.org>
parents:
diff changeset
3 # Contact: email-sig@python.org
d5f3c2f416f2 Copying the email package back, despite its failings.
Guido van Rossum <guido@python.org>
parents:
diff changeset
4
d5f3c2f416f2 Copying the email package back, despite its failings.
Guido van Rossum <guido@python.org>
parents:
diff changeset
5 """email package exception classes."""
d5f3c2f416f2 Copying the email package back, despite its failings.
Guido van Rossum <guido@python.org>
parents:
diff changeset
6
d5f3c2f416f2 Copying the email package back, despite its failings.
Guido van Rossum <guido@python.org>
parents:
diff changeset
7
d5f3c2f416f2 Copying the email package back, despite its failings.
Guido van Rossum <guido@python.org>
parents:
diff changeset
8 class MessageError(Exception):
d5f3c2f416f2 Copying the email package back, despite its failings.
Guido van Rossum <guido@python.org>
parents:
diff changeset
9 """Base class for errors in the email package."""
d5f3c2f416f2 Copying the email package back, despite its failings.
Guido van Rossum <guido@python.org>
parents:
diff changeset
10
d5f3c2f416f2 Copying the email package back, despite its failings.
Guido van Rossum <guido@python.org>
parents:
diff changeset
11
d5f3c2f416f2 Copying the email package back, despite its failings.
Guido van Rossum <guido@python.org>
parents:
diff changeset
12 class MessageParseError(MessageError):
d5f3c2f416f2 Copying the email package back, despite its failings.
Guido van Rossum <guido@python.org>
parents:
diff changeset
13 """Base class for message parsing errors."""
d5f3c2f416f2 Copying the email package back, despite its failings.
Guido van Rossum <guido@python.org>
parents:
diff changeset
14
d5f3c2f416f2 Copying the email package back, despite its failings.
Guido van Rossum <guido@python.org>
parents:
diff changeset
15
d5f3c2f416f2 Copying the email package back, despite its failings.
Guido van Rossum <guido@python.org>
parents:
diff changeset
16 class HeaderParseError(MessageParseError):
d5f3c2f416f2 Copying the email package back, despite its failings.
Guido van Rossum <guido@python.org>
parents:
diff changeset
17 """Error while parsing headers."""
d5f3c2f416f2 Copying the email package back, despite its failings.
Guido van Rossum <guido@python.org>
parents:
diff changeset
18
d5f3c2f416f2 Copying the email package back, despite its failings.
Guido van Rossum <guido@python.org>
parents:
diff changeset
19
d5f3c2f416f2 Copying the email package back, despite its failings.
Guido van Rossum <guido@python.org>
parents:
diff changeset
20 class BoundaryError(MessageParseError):
d5f3c2f416f2 Copying the email package back, despite its failings.
Guido van Rossum <guido@python.org>
parents:
diff changeset
21 """Couldn't find terminating boundary."""
d5f3c2f416f2 Copying the email package back, despite its failings.
Guido van Rossum <guido@python.org>
parents:
diff changeset
22
d5f3c2f416f2 Copying the email package back, despite its failings.
Guido van Rossum <guido@python.org>
parents:
diff changeset
23
d5f3c2f416f2 Copying the email package back, despite its failings.
Guido van Rossum <guido@python.org>
parents:
diff changeset
24 class MultipartConversionError(MessageError, TypeError):
d5f3c2f416f2 Copying the email package back, despite its failings.
Guido van Rossum <guido@python.org>
parents:
diff changeset
25 """Conversion to a multipart is prohibited."""
d5f3c2f416f2 Copying the email package back, despite its failings.
Guido van Rossum <guido@python.org>
parents:
diff changeset
26
d5f3c2f416f2 Copying the email package back, despite its failings.
Guido van Rossum <guido@python.org>
parents:
diff changeset
27
d5f3c2f416f2 Copying the email package back, despite its failings.
Guido van Rossum <guido@python.org>
parents:
diff changeset
28 class CharsetError(MessageError):
d5f3c2f416f2 Copying the email package back, despite its failings.
Guido van Rossum <guido@python.org>
parents:
diff changeset
29 """An illegal charset was given."""
d5f3c2f416f2 Copying the email package back, despite its failings.
Guido van Rossum <guido@python.org>
parents:
diff changeset
30
d5f3c2f416f2 Copying the email package back, despite its failings.
Guido van Rossum <guido@python.org>
parents:
diff changeset
31
d5f3c2f416f2 Copying the email package back, despite its failings.
Guido van Rossum <guido@python.org>
parents:
diff changeset
32 # These are parsing defects which the parser was able to work around.
77148
0189b9d2d6bc #12586: add provisional email policy with new header parsing and folding.
R David Murray <rdmurray@bitdance.com>
parents: 70925
diff changeset
33 class MessageDefect(ValueError):
43019
d5f3c2f416f2 Copying the email package back, despite its failings.
Guido van Rossum <guido@python.org>
parents:
diff changeset
34 """Base class for a message defect."""
d5f3c2f416f2 Copying the email package back, despite its failings.
Guido van Rossum <guido@python.org>
parents:
diff changeset
35
d5f3c2f416f2 Copying the email package back, despite its failings.
Guido van Rossum <guido@python.org>
parents:
diff changeset
36 def __init__(self, line=None):
77391
10a8ad665749 Now that Defects are Exception subclasses, call super.
R David Murray <rdmurray@bitdance.com>
parents: 77198
diff changeset
37 if line is not None:
10a8ad665749 Now that Defects are Exception subclasses, call super.
R David Murray <rdmurray@bitdance.com>
parents: 77198
diff changeset
38 super().__init__(line)
43019
d5f3c2f416f2 Copying the email package back, despite its failings.
Guido van Rossum <guido@python.org>
parents:
diff changeset
39 self.line = line
d5f3c2f416f2 Copying the email package back, despite its failings.
Guido van Rossum <guido@python.org>
parents:
diff changeset
40
d5f3c2f416f2 Copying the email package back, despite its failings.
Guido van Rossum <guido@python.org>
parents:
diff changeset
41 class NoBoundaryInMultipartDefect(MessageDefect):
d5f3c2f416f2 Copying the email package back, despite its failings.
Guido van Rossum <guido@python.org>
parents:
diff changeset
42 """A message claimed to be a multipart but had no boundary parameter."""
d5f3c2f416f2 Copying the email package back, despite its failings.
Guido van Rossum <guido@python.org>
parents:
diff changeset
43
d5f3c2f416f2 Copying the email package back, despite its failings.
Guido van Rossum <guido@python.org>
parents:
diff changeset
44 class StartBoundaryNotFoundDefect(MessageDefect):
d5f3c2f416f2 Copying the email package back, despite its failings.
Guido van Rossum <guido@python.org>
parents:
diff changeset
45 """The claimed start boundary was never found."""
d5f3c2f416f2 Copying the email package back, despite its failings.
Guido van Rossum <guido@python.org>
parents:
diff changeset
46
77198
81e008f13b4f #12515: email now registers a defect if the MIME end boundary is missing.
R David Murray <rdmurray@bitdance.com>
parents: 77191
diff changeset
47 class CloseBoundaryNotFoundDefect(MessageDefect):
81e008f13b4f #12515: email now registers a defect if the MIME end boundary is missing.
R David Murray <rdmurray@bitdance.com>
parents: 77191
diff changeset
48 """A start boundary was found, but not the corresponding close boundary."""
81e008f13b4f #12515: email now registers a defect if the MIME end boundary is missing.
R David Murray <rdmurray@bitdance.com>
parents: 77191
diff changeset
49
43019
d5f3c2f416f2 Copying the email package back, despite its failings.
Guido van Rossum <guido@python.org>
parents:
diff changeset
50 class FirstHeaderLineIsContinuationDefect(MessageDefect):
d5f3c2f416f2 Copying the email package back, despite its failings.
Guido van Rossum <guido@python.org>
parents:
diff changeset
51 """A message had a continuation line as its first header line."""
d5f3c2f416f2 Copying the email package back, despite its failings.
Guido van Rossum <guido@python.org>
parents:
diff changeset
52
d5f3c2f416f2 Copying the email package back, despite its failings.
Guido van Rossum <guido@python.org>
parents:
diff changeset
53 class MisplacedEnvelopeHeaderDefect(MessageDefect):
d5f3c2f416f2 Copying the email package back, despite its failings.
Guido van Rossum <guido@python.org>
parents:
diff changeset
54 """A 'Unix-from' header was found in the middle of a header block."""
d5f3c2f416f2 Copying the email package back, despite its failings.
Guido van Rossum <guido@python.org>
parents:
diff changeset
55
77191
0869f5f47608 #14925: email now registers a defect for missing header/body separator.
R David Murray <rdmurray@bitdance.com>
parents: 77148
diff changeset
56 class MissingHeaderBodySeparatorDefect(MessageDefect):
0869f5f47608 #14925: email now registers a defect for missing header/body separator.
R David Murray <rdmurray@bitdance.com>
parents: 77148
diff changeset
57 """Found line with no leading whitespace and no colon before blank line."""
0869f5f47608 #14925: email now registers a defect for missing header/body separator.
R David Murray <rdmurray@bitdance.com>
parents: 77148
diff changeset
58 # XXX: backward compatibility, just in case (it was never emitted).
0869f5f47608 #14925: email now registers a defect for missing header/body separator.
R David Murray <rdmurray@bitdance.com>
parents: 77148
diff changeset
59 MalformedHeaderDefect = MissingHeaderBodySeparatorDefect
43019
d5f3c2f416f2 Copying the email package back, despite its failings.
Guido van Rossum <guido@python.org>
parents:
diff changeset
60
d5f3c2f416f2 Copying the email package back, despite its failings.
Guido van Rossum <guido@python.org>
parents:
diff changeset
61 class MultipartInvariantViolationDefect(MessageDefect):
d5f3c2f416f2 Copying the email package back, despite its failings.
Guido van Rossum <guido@python.org>
parents:
diff changeset
62 """A message claimed to be a multipart but no subparts were found."""
70925
5a2602939d5d #1874: detect invalid multipart CTE and report it as a defect.
R David Murray <rdmurray@bitdance.com>
parents: 69428
diff changeset
63
5a2602939d5d #1874: detect invalid multipart CTE and report it as a defect.
R David Murray <rdmurray@bitdance.com>
parents: 69428
diff changeset
64 class InvalidMultipartContentTransferEncodingDefect(MessageDefect):
5a2602939d5d #1874: detect invalid multipart CTE and report it as a defect.
R David Murray <rdmurray@bitdance.com>
parents: 69428
diff changeset
65 """An invalid content transfer encoding was set on the multipart itself."""
77148
0189b9d2d6bc #12586: add provisional email policy with new header parsing and folding.
R David Murray <rdmurray@bitdance.com>
parents: 70925
diff changeset
66
0189b9d2d6bc #12586: add provisional email policy with new header parsing and folding.
R David Murray <rdmurray@bitdance.com>
parents: 70925
diff changeset
67 class UndecodableBytesDefect(MessageDefect):
0189b9d2d6bc #12586: add provisional email policy with new header parsing and folding.
R David Murray <rdmurray@bitdance.com>
parents: 70925
diff changeset
68 """Header contained bytes that could not be decoded"""
0189b9d2d6bc #12586: add provisional email policy with new header parsing and folding.
R David Murray <rdmurray@bitdance.com>
parents: 70925
diff changeset
69
0189b9d2d6bc #12586: add provisional email policy with new header parsing and folding.
R David Murray <rdmurray@bitdance.com>
parents: 70925
diff changeset
70 class InvalidBase64PaddingDefect(MessageDefect):
0189b9d2d6bc #12586: add provisional email policy with new header parsing and folding.
R David Murray <rdmurray@bitdance.com>
parents: 70925
diff changeset
71 """base64 encoded sequence had an incorrect length"""
0189b9d2d6bc #12586: add provisional email policy with new header parsing and folding.
R David Murray <rdmurray@bitdance.com>
parents: 70925
diff changeset
72
0189b9d2d6bc #12586: add provisional email policy with new header parsing and folding.
R David Murray <rdmurray@bitdance.com>
parents: 70925
diff changeset
73 class InvalidBase64CharactersDefect(MessageDefect):
0189b9d2d6bc #12586: add provisional email policy with new header parsing and folding.
R David Murray <rdmurray@bitdance.com>
parents: 70925
diff changeset
74 """base64 encoded sequence had characters not in base64 alphabet"""
0189b9d2d6bc #12586: add provisional email policy with new header parsing and folding.
R David Murray <rdmurray@bitdance.com>
parents: 70925
diff changeset
75
0189b9d2d6bc #12586: add provisional email policy with new header parsing and folding.
R David Murray <rdmurray@bitdance.com>
parents: 70925
diff changeset
76 # These errors are specific to header parsing.
0189b9d2d6bc #12586: add provisional email policy with new header parsing and folding.
R David Murray <rdmurray@bitdance.com>
parents: 70925
diff changeset
77
0189b9d2d6bc #12586: add provisional email policy with new header parsing and folding.
R David Murray <rdmurray@bitdance.com>
parents: 70925
diff changeset
78 class HeaderDefect(MessageDefect):
0189b9d2d6bc #12586: add provisional email policy with new header parsing and folding.
R David Murray <rdmurray@bitdance.com>
parents: 70925
diff changeset
79 """Base class for a header defect."""
0189b9d2d6bc #12586: add provisional email policy with new header parsing and folding.
R David Murray <rdmurray@bitdance.com>
parents: 70925
diff changeset
80
77391
10a8ad665749 Now that Defects are Exception subclasses, call super.
R David Murray <rdmurray@bitdance.com>
parents: 77198
diff changeset
81 def __init__(self, *args, **kw):
10a8ad665749 Now that Defects are Exception subclasses, call super.
R David Murray <rdmurray@bitdance.com>
parents: 77198
diff changeset
82 super().__init__(*args, **kw)
10a8ad665749 Now that Defects are Exception subclasses, call super.
R David Murray <rdmurray@bitdance.com>
parents: 77198
diff changeset
83
77148
0189b9d2d6bc #12586: add provisional email policy with new header parsing and folding.
R David Murray <rdmurray@bitdance.com>
parents: 70925
diff changeset
84 class InvalidHeaderDefect(HeaderDefect):
0189b9d2d6bc #12586: add provisional email policy with new header parsing and folding.
R David Murray <rdmurray@bitdance.com>
parents: 70925
diff changeset
85 """Header is not valid, message gives details."""
0189b9d2d6bc #12586: add provisional email policy with new header parsing and folding.
R David Murray <rdmurray@bitdance.com>
parents: 70925
diff changeset
86
0189b9d2d6bc #12586: add provisional email policy with new header parsing and folding.
R David Murray <rdmurray@bitdance.com>
parents: 70925
diff changeset
87 class HeaderMissingRequiredValue(HeaderDefect):
0189b9d2d6bc #12586: add provisional email policy with new header parsing and folding.
R David Murray <rdmurray@bitdance.com>
parents: 70925
diff changeset
88 """A header that must have a value had none"""
0189b9d2d6bc #12586: add provisional email policy with new header parsing and folding.
R David Murray <rdmurray@bitdance.com>
parents: 70925
diff changeset
89
0189b9d2d6bc #12586: add provisional email policy with new header parsing and folding.
R David Murray <rdmurray@bitdance.com>
parents: 70925
diff changeset
90 class NonPrintableDefect(HeaderDefect):
0189b9d2d6bc #12586: add provisional email policy with new header parsing and folding.
R David Murray <rdmurray@bitdance.com>
parents: 70925
diff changeset
91 """ASCII characters outside the ascii-printable range found"""
0189b9d2d6bc #12586: add provisional email policy with new header parsing and folding.
R David Murray <rdmurray@bitdance.com>
parents: 70925
diff changeset
92
0189b9d2d6bc #12586: add provisional email policy with new header parsing and folding.
R David Murray <rdmurray@bitdance.com>
parents: 70925
diff changeset
93 def __init__(self, non_printables):
0189b9d2d6bc #12586: add provisional email policy with new header parsing and folding.
R David Murray <rdmurray@bitdance.com>
parents: 70925
diff changeset
94 super().__init__(non_printables)
0189b9d2d6bc #12586: add provisional email policy with new header parsing and folding.
R David Murray <rdmurray@bitdance.com>
parents: 70925
diff changeset
95 self.non_printables = non_printables
0189b9d2d6bc #12586: add provisional email policy with new header parsing and folding.
R David Murray <rdmurray@bitdance.com>
parents: 70925
diff changeset
96
0189b9d2d6bc #12586: add provisional email policy with new header parsing and folding.
R David Murray <rdmurray@bitdance.com>
parents: 70925
diff changeset
97 def __str__(self):
0189b9d2d6bc #12586: add provisional email policy with new header parsing and folding.
R David Murray <rdmurray@bitdance.com>
parents: 70925
diff changeset
98 return ("the following ASCII non-printables found in header: "
0189b9d2d6bc #12586: add provisional email policy with new header parsing and folding.
R David Murray <rdmurray@bitdance.com>
parents: 70925
diff changeset
99 "{}".format(self.non_printables))
0189b9d2d6bc #12586: add provisional email policy with new header parsing and folding.
R David Murray <rdmurray@bitdance.com>
parents: 70925
diff changeset
100
0189b9d2d6bc #12586: add provisional email policy with new header parsing and folding.
R David Murray <rdmurray@bitdance.com>
parents: 70925
diff changeset
101 class ObsoleteHeaderDefect(HeaderDefect):
0189b9d2d6bc #12586: add provisional email policy with new header parsing and folding.
R David Murray <rdmurray@bitdance.com>
parents: 70925
diff changeset
102 """Header uses syntax declared obsolete by RFC 5322"""
0189b9d2d6bc #12586: add provisional email policy with new header parsing and folding.
R David Murray <rdmurray@bitdance.com>
parents: 70925
diff changeset
103
0189b9d2d6bc #12586: add provisional email policy with new header parsing and folding.
R David Murray <rdmurray@bitdance.com>
parents: 70925
diff changeset
104 class NonASCIILocalPartDefect(HeaderDefect):
0189b9d2d6bc #12586: add provisional email policy with new header parsing and folding.
R David Murray <rdmurray@bitdance.com>
parents: 70925
diff changeset
105 """local_part contains non-ASCII characters"""
0189b9d2d6bc #12586: add provisional email policy with new header parsing and folding.
R David Murray <rdmurray@bitdance.com>
parents: 70925
diff changeset
106 # This defect only occurs during unicode parsing, not when
0189b9d2d6bc #12586: add provisional email policy with new header parsing and folding.
R David Murray <rdmurray@bitdance.com>
parents: 70925
diff changeset
107 # parsing messages decoded from binary.