Add files using upload-large-folder tool
Browse filesThis view is limited to 50 files because it contains too many changes.
See raw diff
- mgm/lib/python3.10/__pycache__/__future__.cpython-310.pyc +0 -0
- mgm/lib/python3.10/__pycache__/_bootsubprocess.cpython-310.pyc +0 -0
- mgm/lib/python3.10/__pycache__/_sitebuiltins.cpython-310.pyc +0 -0
- mgm/lib/python3.10/__pycache__/_sysconfigdata_x86_64_conda_linux_gnu.cpython-310.pyc +0 -0
- mgm/lib/python3.10/__pycache__/antigravity.cpython-310.pyc +0 -0
- mgm/lib/python3.10/__pycache__/base64.cpython-310.pyc +0 -0
- mgm/lib/python3.10/__pycache__/binhex.cpython-310.pyc +0 -0
- mgm/lib/python3.10/__pycache__/cProfile.cpython-310.pyc +0 -0
- mgm/lib/python3.10/__pycache__/contextvars.cpython-310.pyc +0 -0
- mgm/lib/python3.10/__pycache__/copy.cpython-310.pyc +0 -0
- mgm/lib/python3.10/__pycache__/dataclasses.cpython-310.pyc +0 -0
- mgm/lib/python3.10/__pycache__/datetime.cpython-310.pyc +0 -0
- mgm/lib/python3.10/__pycache__/difflib.cpython-310.pyc +0 -0
- mgm/lib/python3.10/__pycache__/dis.cpython-310.pyc +0 -0
- mgm/lib/python3.10/__pycache__/enum.cpython-310.pyc +0 -0
- mgm/lib/python3.10/__pycache__/fnmatch.cpython-310.pyc +0 -0
- mgm/lib/python3.10/__pycache__/imp.cpython-310.pyc +0 -0
- mgm/lib/python3.10/__pycache__/locale.cpython-310.pyc +0 -0
- mgm/lib/python3.10/__pycache__/modulefinder.cpython-310.pyc +0 -0
- mgm/lib/python3.10/__pycache__/netrc.cpython-310.pyc +0 -0
- mgm/lib/python3.10/__pycache__/optparse.cpython-310.pyc +0 -0
- mgm/lib/python3.10/__pycache__/pdb.cpython-310.pyc +0 -0
- mgm/lib/python3.10/__pycache__/pickle.cpython-310.pyc +0 -0
- mgm/lib/python3.10/__pycache__/platform.cpython-310.pyc +0 -0
- mgm/lib/python3.10/__pycache__/pyclbr.cpython-310.pyc +0 -0
- mgm/lib/python3.10/__pycache__/quopri.cpython-310.pyc +0 -0
- mgm/lib/python3.10/__pycache__/reprlib.cpython-310.pyc +0 -0
- mgm/lib/python3.10/__pycache__/selectors.cpython-310.pyc +0 -0
- mgm/lib/python3.10/__pycache__/signal.cpython-310.pyc +0 -0
- mgm/lib/python3.10/__pycache__/site.cpython-310.pyc +0 -0
- mgm/lib/python3.10/__pycache__/smtpd.cpython-310.pyc +0 -0
- mgm/lib/python3.10/__pycache__/string.cpython-310.pyc +0 -0
- mgm/lib/python3.10/__pycache__/stringprep.cpython-310.pyc +0 -0
- mgm/lib/python3.10/__pycache__/sunau.cpython-310.pyc +0 -0
- mgm/lib/python3.10/__pycache__/sysconfig.cpython-310.pyc +0 -0
- mgm/lib/python3.10/__pycache__/tabnanny.cpython-310.pyc +0 -0
- mgm/lib/python3.10/__pycache__/tempfile.cpython-310.pyc +0 -0
- mgm/lib/python3.10/__pycache__/xdrlib.cpython-310.pyc +0 -0
- mgm/lib/python3.10/__pycache__/zipimport.cpython-310.pyc +0 -0
- mgm/lib/python3.10/email/__init__.py +62 -0
- mgm/lib/python3.10/email/__pycache__/_encoded_words.cpython-310.pyc +0 -0
- mgm/lib/python3.10/email/__pycache__/_header_value_parser.cpython-310.pyc +0 -0
- mgm/lib/python3.10/email/__pycache__/_policybase.cpython-310.pyc +0 -0
- mgm/lib/python3.10/email/__pycache__/errors.cpython-310.pyc +0 -0
- mgm/lib/python3.10/email/__pycache__/headerregistry.cpython-310.pyc +0 -0
- mgm/lib/python3.10/email/__pycache__/iterators.cpython-310.pyc +0 -0
- mgm/lib/python3.10/email/__pycache__/quoprimime.cpython-310.pyc +0 -0
- mgm/lib/python3.10/email/_encoded_words.py +233 -0
- mgm/lib/python3.10/email/_header_value_parser.py +0 -0
- mgm/lib/python3.10/email/_policybase.py +382 -0
mgm/lib/python3.10/__pycache__/__future__.cpython-310.pyc
ADDED
|
Binary file (4.13 kB). View file
|
|
|
mgm/lib/python3.10/__pycache__/_bootsubprocess.cpython-310.pyc
ADDED
|
Binary file (2.55 kB). View file
|
|
|
mgm/lib/python3.10/__pycache__/_sitebuiltins.cpython-310.pyc
ADDED
|
Binary file (3.54 kB). View file
|
|
|
mgm/lib/python3.10/__pycache__/_sysconfigdata_x86_64_conda_linux_gnu.cpython-310.pyc
ADDED
|
Binary file (59.9 kB). View file
|
|
|
mgm/lib/python3.10/__pycache__/antigravity.cpython-310.pyc
ADDED
|
Binary file (1.08 kB). View file
|
|
|
mgm/lib/python3.10/__pycache__/base64.cpython-310.pyc
ADDED
|
Binary file (17.4 kB). View file
|
|
|
mgm/lib/python3.10/__pycache__/binhex.cpython-310.pyc
ADDED
|
Binary file (12.9 kB). View file
|
|
|
mgm/lib/python3.10/__pycache__/cProfile.cpython-310.pyc
ADDED
|
Binary file (5.11 kB). View file
|
|
|
mgm/lib/python3.10/__pycache__/contextvars.cpython-310.pyc
ADDED
|
Binary file (500 Bytes). View file
|
|
|
mgm/lib/python3.10/__pycache__/copy.cpython-310.pyc
ADDED
|
Binary file (6.99 kB). View file
|
|
|
mgm/lib/python3.10/__pycache__/dataclasses.cpython-310.pyc
ADDED
|
Binary file (26.8 kB). View file
|
|
|
mgm/lib/python3.10/__pycache__/datetime.cpython-310.pyc
ADDED
|
Binary file (56.5 kB). View file
|
|
|
mgm/lib/python3.10/__pycache__/difflib.cpython-310.pyc
ADDED
|
Binary file (59.2 kB). View file
|
|
|
mgm/lib/python3.10/__pycache__/dis.cpython-310.pyc
ADDED
|
Binary file (15.9 kB). View file
|
|
|
mgm/lib/python3.10/__pycache__/enum.cpython-310.pyc
ADDED
|
Binary file (26.3 kB). View file
|
|
|
mgm/lib/python3.10/__pycache__/fnmatch.cpython-310.pyc
ADDED
|
Binary file (4.5 kB). View file
|
|
|
mgm/lib/python3.10/__pycache__/imp.cpython-310.pyc
ADDED
|
Binary file (9.78 kB). View file
|
|
|
mgm/lib/python3.10/__pycache__/locale.cpython-310.pyc
ADDED
|
Binary file (46.4 kB). View file
|
|
|
mgm/lib/python3.10/__pycache__/modulefinder.cpython-310.pyc
ADDED
|
Binary file (16.4 kB). View file
|
|
|
mgm/lib/python3.10/__pycache__/netrc.cpython-310.pyc
ADDED
|
Binary file (4.19 kB). View file
|
|
|
mgm/lib/python3.10/__pycache__/optparse.cpython-310.pyc
ADDED
|
Binary file (48 kB). View file
|
|
|
mgm/lib/python3.10/__pycache__/pdb.cpython-310.pyc
ADDED
|
Binary file (47.4 kB). View file
|
|
|
mgm/lib/python3.10/__pycache__/pickle.cpython-310.pyc
ADDED
|
Binary file (46.9 kB). View file
|
|
|
mgm/lib/python3.10/__pycache__/platform.cpython-310.pyc
ADDED
|
Binary file (27.7 kB). View file
|
|
|
mgm/lib/python3.10/__pycache__/pyclbr.cpython-310.pyc
ADDED
|
Binary file (10 kB). View file
|
|
|
mgm/lib/python3.10/__pycache__/quopri.cpython-310.pyc
ADDED
|
Binary file (6.05 kB). View file
|
|
|
mgm/lib/python3.10/__pycache__/reprlib.cpython-310.pyc
ADDED
|
Binary file (5.5 kB). View file
|
|
|
mgm/lib/python3.10/__pycache__/selectors.cpython-310.pyc
ADDED
|
Binary file (17.4 kB). View file
|
|
|
mgm/lib/python3.10/__pycache__/signal.cpython-310.pyc
ADDED
|
Binary file (2.93 kB). View file
|
|
|
mgm/lib/python3.10/__pycache__/site.cpython-310.pyc
ADDED
|
Binary file (17.9 kB). View file
|
|
|
mgm/lib/python3.10/__pycache__/smtpd.cpython-310.pyc
ADDED
|
Binary file (26.4 kB). View file
|
|
|
mgm/lib/python3.10/__pycache__/string.cpython-310.pyc
ADDED
|
Binary file (7.36 kB). View file
|
|
|
mgm/lib/python3.10/__pycache__/stringprep.cpython-310.pyc
ADDED
|
Binary file (17.1 kB). View file
|
|
|
mgm/lib/python3.10/__pycache__/sunau.cpython-310.pyc
ADDED
|
Binary file (16.5 kB). View file
|
|
|
mgm/lib/python3.10/__pycache__/sysconfig.cpython-310.pyc
ADDED
|
Binary file (17.8 kB). View file
|
|
|
mgm/lib/python3.10/__pycache__/tabnanny.cpython-310.pyc
ADDED
|
Binary file (7.2 kB). View file
|
|
|
mgm/lib/python3.10/__pycache__/tempfile.cpython-310.pyc
ADDED
|
Binary file (24.6 kB). View file
|
|
|
mgm/lib/python3.10/__pycache__/xdrlib.cpython-310.pyc
ADDED
|
Binary file (7.88 kB). View file
|
|
|
mgm/lib/python3.10/__pycache__/zipimport.cpython-310.pyc
ADDED
|
Binary file (17.3 kB). View file
|
|
|
mgm/lib/python3.10/email/__init__.py
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Copyright (C) 2001-2007 Python Software Foundation
|
| 2 |
+
# Author: Barry Warsaw
|
| 3 |
+
# Contact: email-sig@python.org
|
| 4 |
+
|
| 5 |
+
"""A package for parsing, handling, and generating email messages."""
|
| 6 |
+
|
| 7 |
+
__all__ = [
|
| 8 |
+
'base64mime',
|
| 9 |
+
'charset',
|
| 10 |
+
'encoders',
|
| 11 |
+
'errors',
|
| 12 |
+
'feedparser',
|
| 13 |
+
'generator',
|
| 14 |
+
'header',
|
| 15 |
+
'iterators',
|
| 16 |
+
'message',
|
| 17 |
+
'message_from_file',
|
| 18 |
+
'message_from_binary_file',
|
| 19 |
+
'message_from_string',
|
| 20 |
+
'message_from_bytes',
|
| 21 |
+
'mime',
|
| 22 |
+
'parser',
|
| 23 |
+
'quoprimime',
|
| 24 |
+
'utils',
|
| 25 |
+
]
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
# Some convenience routines. Don't import Parser and Message as side-effects
|
| 30 |
+
# of importing email since those cascadingly import most of the rest of the
|
| 31 |
+
# email package.
|
| 32 |
+
def message_from_string(s, *args, **kws):
|
| 33 |
+
"""Parse a string into a Message object model.
|
| 34 |
+
|
| 35 |
+
Optional _class and strict are passed to the Parser constructor.
|
| 36 |
+
"""
|
| 37 |
+
from email.parser import Parser
|
| 38 |
+
return Parser(*args, **kws).parsestr(s)
|
| 39 |
+
|
| 40 |
+
def message_from_bytes(s, *args, **kws):
|
| 41 |
+
"""Parse a bytes string into a Message object model.
|
| 42 |
+
|
| 43 |
+
Optional _class and strict are passed to the Parser constructor.
|
| 44 |
+
"""
|
| 45 |
+
from email.parser import BytesParser
|
| 46 |
+
return BytesParser(*args, **kws).parsebytes(s)
|
| 47 |
+
|
| 48 |
+
def message_from_file(fp, *args, **kws):
|
| 49 |
+
"""Read a file and parse its contents into a Message object model.
|
| 50 |
+
|
| 51 |
+
Optional _class and strict are passed to the Parser constructor.
|
| 52 |
+
"""
|
| 53 |
+
from email.parser import Parser
|
| 54 |
+
return Parser(*args, **kws).parse(fp)
|
| 55 |
+
|
| 56 |
+
def message_from_binary_file(fp, *args, **kws):
|
| 57 |
+
"""Read a binary file and parse its contents into a Message object model.
|
| 58 |
+
|
| 59 |
+
Optional _class and strict are passed to the Parser constructor.
|
| 60 |
+
"""
|
| 61 |
+
from email.parser import BytesParser
|
| 62 |
+
return BytesParser(*args, **kws).parse(fp)
|
mgm/lib/python3.10/email/__pycache__/_encoded_words.cpython-310.pyc
ADDED
|
Binary file (5.99 kB). View file
|
|
|
mgm/lib/python3.10/email/__pycache__/_header_value_parser.cpython-310.pyc
ADDED
|
Binary file (78.1 kB). View file
|
|
|
mgm/lib/python3.10/email/__pycache__/_policybase.cpython-310.pyc
ADDED
|
Binary file (15.5 kB). View file
|
|
|
mgm/lib/python3.10/email/__pycache__/errors.cpython-310.pyc
ADDED
|
Binary file (6.1 kB). View file
|
|
|
mgm/lib/python3.10/email/__pycache__/headerregistry.cpython-310.pyc
ADDED
|
Binary file (22.2 kB). View file
|
|
|
mgm/lib/python3.10/email/__pycache__/iterators.cpython-310.pyc
ADDED
|
Binary file (2.22 kB). View file
|
|
|
mgm/lib/python3.10/email/__pycache__/quoprimime.cpython-310.pyc
ADDED
|
Binary file (7.88 kB). View file
|
|
|
mgm/lib/python3.10/email/_encoded_words.py
ADDED
|
@@ -0,0 +1,233 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
""" Routines for manipulating RFC2047 encoded words.
|
| 2 |
+
|
| 3 |
+
This is currently a package-private API, but will be considered for promotion
|
| 4 |
+
to a public API if there is demand.
|
| 5 |
+
|
| 6 |
+
"""
|
| 7 |
+
|
| 8 |
+
# An ecoded word looks like this:
|
| 9 |
+
#
|
| 10 |
+
# =?charset[*lang]?cte?encoded_string?=
|
| 11 |
+
#
|
| 12 |
+
# for more information about charset see the charset module. Here it is one
|
| 13 |
+
# of the preferred MIME charset names (hopefully; you never know when parsing).
|
| 14 |
+
# cte (Content Transfer Encoding) is either 'q' or 'b' (ignoring case). In
|
| 15 |
+
# theory other letters could be used for other encodings, but in practice this
|
| 16 |
+
# (almost?) never happens. There could be a public API for adding entries
|
| 17 |
+
# to the CTE tables, but YAGNI for now. 'q' is Quoted Printable, 'b' is
|
| 18 |
+
# Base64. The meaning of encoded_string should be obvious. 'lang' is optional
|
| 19 |
+
# as indicated by the brackets (they are not part of the syntax) but is almost
|
| 20 |
+
# never encountered in practice.
|
| 21 |
+
#
|
| 22 |
+
# The general interface for a CTE decoder is that it takes the encoded_string
|
| 23 |
+
# as its argument, and returns a tuple (cte_decoded_string, defects). The
|
| 24 |
+
# cte_decoded_string is the original binary that was encoded using the
|
| 25 |
+
# specified cte. 'defects' is a list of MessageDefect instances indicating any
|
| 26 |
+
# problems encountered during conversion. 'charset' and 'lang' are the
|
| 27 |
+
# corresponding strings extracted from the EW, case preserved.
|
| 28 |
+
#
|
| 29 |
+
# The general interface for a CTE encoder is that it takes a binary sequence
|
| 30 |
+
# as input and returns the cte_encoded_string, which is an ascii-only string.
|
| 31 |
+
#
|
| 32 |
+
# Each decoder must also supply a length function that takes the binary
|
| 33 |
+
# sequence as its argument and returns the length of the resulting encoded
|
| 34 |
+
# string.
|
| 35 |
+
#
|
| 36 |
+
# The main API functions for the module are decode, which calls the decoder
|
| 37 |
+
# referenced by the cte specifier, and encode, which adds the appropriate
|
| 38 |
+
# RFC 2047 "chrome" to the encoded string, and can optionally automatically
|
| 39 |
+
# select the shortest possible encoding. See their docstrings below for
|
| 40 |
+
# details.
|
| 41 |
+
|
| 42 |
+
import re
|
| 43 |
+
import base64
|
| 44 |
+
import binascii
|
| 45 |
+
import functools
|
| 46 |
+
from string import ascii_letters, digits
|
| 47 |
+
from email import errors
|
| 48 |
+
|
| 49 |
+
__all__ = ['decode_q',
|
| 50 |
+
'encode_q',
|
| 51 |
+
'decode_b',
|
| 52 |
+
'encode_b',
|
| 53 |
+
'len_q',
|
| 54 |
+
'len_b',
|
| 55 |
+
'decode',
|
| 56 |
+
'encode',
|
| 57 |
+
]
|
| 58 |
+
|
| 59 |
+
#
|
| 60 |
+
# Quoted Printable
|
| 61 |
+
#
|
| 62 |
+
|
| 63 |
+
# regex based decoder.
|
| 64 |
+
_q_byte_subber = functools.partial(re.compile(br'=([a-fA-F0-9]{2})').sub,
|
| 65 |
+
lambda m: bytes.fromhex(m.group(1).decode()))
|
| 66 |
+
|
| 67 |
+
def decode_q(encoded):
|
| 68 |
+
encoded = encoded.replace(b'_', b' ')
|
| 69 |
+
return _q_byte_subber(encoded), []
|
| 70 |
+
|
| 71 |
+
|
| 72 |
+
# dict mapping bytes to their encoded form
|
| 73 |
+
class _QByteMap(dict):
|
| 74 |
+
|
| 75 |
+
safe = b'-!*+/' + ascii_letters.encode('ascii') + digits.encode('ascii')
|
| 76 |
+
|
| 77 |
+
def __missing__(self, key):
|
| 78 |
+
if key in self.safe:
|
| 79 |
+
self[key] = chr(key)
|
| 80 |
+
else:
|
| 81 |
+
self[key] = "={:02X}".format(key)
|
| 82 |
+
return self[key]
|
| 83 |
+
|
| 84 |
+
_q_byte_map = _QByteMap()
|
| 85 |
+
|
| 86 |
+
# In headers spaces are mapped to '_'.
|
| 87 |
+
_q_byte_map[ord(' ')] = '_'
|
| 88 |
+
|
| 89 |
+
def encode_q(bstring):
|
| 90 |
+
return ''.join(_q_byte_map[x] for x in bstring)
|
| 91 |
+
|
| 92 |
+
def len_q(bstring):
|
| 93 |
+
return sum(len(_q_byte_map[x]) for x in bstring)
|
| 94 |
+
|
| 95 |
+
|
| 96 |
+
#
|
| 97 |
+
# Base64
|
| 98 |
+
#
|
| 99 |
+
|
| 100 |
+
def decode_b(encoded):
|
| 101 |
+
# First try encoding with validate=True, fixing the padding if needed.
|
| 102 |
+
# This will succeed only if encoded includes no invalid characters.
|
| 103 |
+
pad_err = len(encoded) % 4
|
| 104 |
+
missing_padding = b'==='[:4-pad_err] if pad_err else b''
|
| 105 |
+
try:
|
| 106 |
+
return (
|
| 107 |
+
base64.b64decode(encoded + missing_padding, validate=True),
|
| 108 |
+
[errors.InvalidBase64PaddingDefect()] if pad_err else [],
|
| 109 |
+
)
|
| 110 |
+
except binascii.Error:
|
| 111 |
+
# Since we had correct padding, this is likely an invalid char error.
|
| 112 |
+
#
|
| 113 |
+
# The non-alphabet characters are ignored as far as padding
|
| 114 |
+
# goes, but we don't know how many there are. So try without adding
|
| 115 |
+
# padding to see if it works.
|
| 116 |
+
try:
|
| 117 |
+
return (
|
| 118 |
+
base64.b64decode(encoded, validate=False),
|
| 119 |
+
[errors.InvalidBase64CharactersDefect()],
|
| 120 |
+
)
|
| 121 |
+
except binascii.Error:
|
| 122 |
+
# Add as much padding as could possibly be necessary (extra padding
|
| 123 |
+
# is ignored).
|
| 124 |
+
try:
|
| 125 |
+
return (
|
| 126 |
+
base64.b64decode(encoded + b'==', validate=False),
|
| 127 |
+
[errors.InvalidBase64CharactersDefect(),
|
| 128 |
+
errors.InvalidBase64PaddingDefect()],
|
| 129 |
+
)
|
| 130 |
+
except binascii.Error:
|
| 131 |
+
# This only happens when the encoded string's length is 1 more
|
| 132 |
+
# than a multiple of 4, which is invalid.
|
| 133 |
+
#
|
| 134 |
+
# bpo-27397: Just return the encoded string since there's no
|
| 135 |
+
# way to decode.
|
| 136 |
+
return encoded, [errors.InvalidBase64LengthDefect()]
|
| 137 |
+
|
| 138 |
+
def encode_b(bstring):
|
| 139 |
+
return base64.b64encode(bstring).decode('ascii')
|
| 140 |
+
|
| 141 |
+
def len_b(bstring):
|
| 142 |
+
groups_of_3, leftover = divmod(len(bstring), 3)
|
| 143 |
+
# 4 bytes out for each 3 bytes (or nonzero fraction thereof) in.
|
| 144 |
+
return groups_of_3 * 4 + (4 if leftover else 0)
|
| 145 |
+
|
| 146 |
+
|
| 147 |
+
_cte_decoders = {
|
| 148 |
+
'q': decode_q,
|
| 149 |
+
'b': decode_b,
|
| 150 |
+
}
|
| 151 |
+
|
| 152 |
+
def decode(ew):
|
| 153 |
+
"""Decode encoded word and return (string, charset, lang, defects) tuple.
|
| 154 |
+
|
| 155 |
+
An RFC 2047/2243 encoded word has the form:
|
| 156 |
+
|
| 157 |
+
=?charset*lang?cte?encoded_string?=
|
| 158 |
+
|
| 159 |
+
where '*lang' may be omitted but the other parts may not be.
|
| 160 |
+
|
| 161 |
+
This function expects exactly such a string (that is, it does not check the
|
| 162 |
+
syntax and may raise errors if the string is not well formed), and returns
|
| 163 |
+
the encoded_string decoded first from its Content Transfer Encoding and
|
| 164 |
+
then from the resulting bytes into unicode using the specified charset. If
|
| 165 |
+
the cte-decoded string does not successfully decode using the specified
|
| 166 |
+
character set, a defect is added to the defects list and the unknown octets
|
| 167 |
+
are replaced by the unicode 'unknown' character \\uFDFF.
|
| 168 |
+
|
| 169 |
+
The specified charset and language are returned. The default for language,
|
| 170 |
+
which is rarely if ever encountered, is the empty string.
|
| 171 |
+
|
| 172 |
+
"""
|
| 173 |
+
_, charset, cte, cte_string, _ = ew.split('?')
|
| 174 |
+
charset, _, lang = charset.partition('*')
|
| 175 |
+
cte = cte.lower()
|
| 176 |
+
# Recover the original bytes and do CTE decoding.
|
| 177 |
+
bstring = cte_string.encode('ascii', 'surrogateescape')
|
| 178 |
+
bstring, defects = _cte_decoders[cte](bstring)
|
| 179 |
+
# Turn the CTE decoded bytes into unicode.
|
| 180 |
+
try:
|
| 181 |
+
string = bstring.decode(charset)
|
| 182 |
+
except UnicodeDecodeError:
|
| 183 |
+
defects.append(errors.UndecodableBytesDefect("Encoded word "
|
| 184 |
+
f"contains bytes not decodable using {charset!r} charset"))
|
| 185 |
+
string = bstring.decode(charset, 'surrogateescape')
|
| 186 |
+
except (LookupError, UnicodeEncodeError):
|
| 187 |
+
string = bstring.decode('ascii', 'surrogateescape')
|
| 188 |
+
if charset.lower() != 'unknown-8bit':
|
| 189 |
+
defects.append(errors.CharsetError(f"Unknown charset {charset!r} "
|
| 190 |
+
f"in encoded word; decoded as unknown bytes"))
|
| 191 |
+
return string, charset, lang, defects
|
| 192 |
+
|
| 193 |
+
|
| 194 |
+
_cte_encoders = {
|
| 195 |
+
'q': encode_q,
|
| 196 |
+
'b': encode_b,
|
| 197 |
+
}
|
| 198 |
+
|
| 199 |
+
_cte_encode_length = {
|
| 200 |
+
'q': len_q,
|
| 201 |
+
'b': len_b,
|
| 202 |
+
}
|
| 203 |
+
|
| 204 |
+
def encode(string, charset='utf-8', encoding=None, lang=''):
|
| 205 |
+
"""Encode string using the CTE encoding that produces the shorter result.
|
| 206 |
+
|
| 207 |
+
Produces an RFC 2047/2243 encoded word of the form:
|
| 208 |
+
|
| 209 |
+
=?charset*lang?cte?encoded_string?=
|
| 210 |
+
|
| 211 |
+
where '*lang' is omitted unless the 'lang' parameter is given a value.
|
| 212 |
+
Optional argument charset (defaults to utf-8) specifies the charset to use
|
| 213 |
+
to encode the string to binary before CTE encoding it. Optional argument
|
| 214 |
+
'encoding' is the cte specifier for the encoding that should be used ('q'
|
| 215 |
+
or 'b'); if it is None (the default) the encoding which produces the
|
| 216 |
+
shortest encoded sequence is used, except that 'q' is preferred if it is up
|
| 217 |
+
to five characters longer. Optional argument 'lang' (default '') gives the
|
| 218 |
+
RFC 2243 language string to specify in the encoded word.
|
| 219 |
+
|
| 220 |
+
"""
|
| 221 |
+
if charset == 'unknown-8bit':
|
| 222 |
+
bstring = string.encode('ascii', 'surrogateescape')
|
| 223 |
+
else:
|
| 224 |
+
bstring = string.encode(charset)
|
| 225 |
+
if encoding is None:
|
| 226 |
+
qlen = _cte_encode_length['q'](bstring)
|
| 227 |
+
blen = _cte_encode_length['b'](bstring)
|
| 228 |
+
# Bias toward q. 5 is arbitrary.
|
| 229 |
+
encoding = 'q' if qlen - blen < 5 else 'b'
|
| 230 |
+
encoded = _cte_encoders[encoding](bstring)
|
| 231 |
+
if lang:
|
| 232 |
+
lang = '*' + lang
|
| 233 |
+
return "=?{}{}?{}?{}?=".format(charset, lang, encoding, encoded)
|
mgm/lib/python3.10/email/_header_value_parser.py
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
mgm/lib/python3.10/email/_policybase.py
ADDED
|
@@ -0,0 +1,382 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Policy framework for the email package.
|
| 2 |
+
|
| 3 |
+
Allows fine grained feature control of how the package parses and emits data.
|
| 4 |
+
"""
|
| 5 |
+
|
| 6 |
+
import abc
|
| 7 |
+
from email import header
|
| 8 |
+
from email import charset as _charset
|
| 9 |
+
from email.utils import _has_surrogates
|
| 10 |
+
|
| 11 |
+
__all__ = [
|
| 12 |
+
'Policy',
|
| 13 |
+
'Compat32',
|
| 14 |
+
'compat32',
|
| 15 |
+
]
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
class _PolicyBase:
|
| 19 |
+
|
| 20 |
+
"""Policy Object basic framework.
|
| 21 |
+
|
| 22 |
+
This class is useless unless subclassed. A subclass should define
|
| 23 |
+
class attributes with defaults for any values that are to be
|
| 24 |
+
managed by the Policy object. The constructor will then allow
|
| 25 |
+
non-default values to be set for these attributes at instance
|
| 26 |
+
creation time. The instance will be callable, taking these same
|
| 27 |
+
attributes keyword arguments, and returning a new instance
|
| 28 |
+
identical to the called instance except for those values changed
|
| 29 |
+
by the keyword arguments. Instances may be added, yielding new
|
| 30 |
+
instances with any non-default values from the right hand
|
| 31 |
+
operand overriding those in the left hand operand. That is,
|
| 32 |
+
|
| 33 |
+
A + B == A(<non-default values of B>)
|
| 34 |
+
|
| 35 |
+
The repr of an instance can be used to reconstruct the object
|
| 36 |
+
if and only if the repr of the values can be used to reconstruct
|
| 37 |
+
those values.
|
| 38 |
+
|
| 39 |
+
"""
|
| 40 |
+
|
| 41 |
+
def __init__(self, **kw):
|
| 42 |
+
"""Create new Policy, possibly overriding some defaults.
|
| 43 |
+
|
| 44 |
+
See class docstring for a list of overridable attributes.
|
| 45 |
+
|
| 46 |
+
"""
|
| 47 |
+
for name, value in kw.items():
|
| 48 |
+
if hasattr(self, name):
|
| 49 |
+
super(_PolicyBase,self).__setattr__(name, value)
|
| 50 |
+
else:
|
| 51 |
+
raise TypeError(
|
| 52 |
+
"{!r} is an invalid keyword argument for {}".format(
|
| 53 |
+
name, self.__class__.__name__))
|
| 54 |
+
|
| 55 |
+
def __repr__(self):
|
| 56 |
+
args = [ "{}={!r}".format(name, value)
|
| 57 |
+
for name, value in self.__dict__.items() ]
|
| 58 |
+
return "{}({})".format(self.__class__.__name__, ', '.join(args))
|
| 59 |
+
|
| 60 |
+
def clone(self, **kw):
|
| 61 |
+
"""Return a new instance with specified attributes changed.
|
| 62 |
+
|
| 63 |
+
The new instance has the same attribute values as the current object,
|
| 64 |
+
except for the changes passed in as keyword arguments.
|
| 65 |
+
|
| 66 |
+
"""
|
| 67 |
+
newpolicy = self.__class__.__new__(self.__class__)
|
| 68 |
+
for attr, value in self.__dict__.items():
|
| 69 |
+
object.__setattr__(newpolicy, attr, value)
|
| 70 |
+
for attr, value in kw.items():
|
| 71 |
+
if not hasattr(self, attr):
|
| 72 |
+
raise TypeError(
|
| 73 |
+
"{!r} is an invalid keyword argument for {}".format(
|
| 74 |
+
attr, self.__class__.__name__))
|
| 75 |
+
object.__setattr__(newpolicy, attr, value)
|
| 76 |
+
return newpolicy
|
| 77 |
+
|
| 78 |
+
def __setattr__(self, name, value):
|
| 79 |
+
if hasattr(self, name):
|
| 80 |
+
msg = "{!r} object attribute {!r} is read-only"
|
| 81 |
+
else:
|
| 82 |
+
msg = "{!r} object has no attribute {!r}"
|
| 83 |
+
raise AttributeError(msg.format(self.__class__.__name__, name))
|
| 84 |
+
|
| 85 |
+
def __add__(self, other):
|
| 86 |
+
"""Non-default values from right operand override those from left.
|
| 87 |
+
|
| 88 |
+
The object returned is a new instance of the subclass.
|
| 89 |
+
|
| 90 |
+
"""
|
| 91 |
+
return self.clone(**other.__dict__)
|
| 92 |
+
|
| 93 |
+
|
| 94 |
+
def _append_doc(doc, added_doc):
|
| 95 |
+
doc = doc.rsplit('\n', 1)[0]
|
| 96 |
+
added_doc = added_doc.split('\n', 1)[1]
|
| 97 |
+
return doc + '\n' + added_doc
|
| 98 |
+
|
| 99 |
+
def _extend_docstrings(cls):
|
| 100 |
+
if cls.__doc__ and cls.__doc__.startswith('+'):
|
| 101 |
+
cls.__doc__ = _append_doc(cls.__bases__[0].__doc__, cls.__doc__)
|
| 102 |
+
for name, attr in cls.__dict__.items():
|
| 103 |
+
if attr.__doc__ and attr.__doc__.startswith('+'):
|
| 104 |
+
for c in (c for base in cls.__bases__ for c in base.mro()):
|
| 105 |
+
doc = getattr(getattr(c, name), '__doc__')
|
| 106 |
+
if doc:
|
| 107 |
+
attr.__doc__ = _append_doc(doc, attr.__doc__)
|
| 108 |
+
break
|
| 109 |
+
return cls
|
| 110 |
+
|
| 111 |
+
|
| 112 |
+
class Policy(_PolicyBase, metaclass=abc.ABCMeta):
|
| 113 |
+
|
| 114 |
+
r"""Controls for how messages are interpreted and formatted.
|
| 115 |
+
|
| 116 |
+
Most of the classes and many of the methods in the email package accept
|
| 117 |
+
Policy objects as parameters. A Policy object contains a set of values and
|
| 118 |
+
functions that control how input is interpreted and how output is rendered.
|
| 119 |
+
For example, the parameter 'raise_on_defect' controls whether or not an RFC
|
| 120 |
+
violation results in an error being raised or not, while 'max_line_length'
|
| 121 |
+
controls the maximum length of output lines when a Message is serialized.
|
| 122 |
+
|
| 123 |
+
Any valid attribute may be overridden when a Policy is created by passing
|
| 124 |
+
it as a keyword argument to the constructor. Policy objects are immutable,
|
| 125 |
+
but a new Policy object can be created with only certain values changed by
|
| 126 |
+
calling the Policy instance with keyword arguments. Policy objects can
|
| 127 |
+
also be added, producing a new Policy object in which the non-default
|
| 128 |
+
attributes set in the right hand operand overwrite those specified in the
|
| 129 |
+
left operand.
|
| 130 |
+
|
| 131 |
+
Settable attributes:
|
| 132 |
+
|
| 133 |
+
raise_on_defect -- If true, then defects should be raised as errors.
|
| 134 |
+
Default: False.
|
| 135 |
+
|
| 136 |
+
linesep -- string containing the value to use as separation
|
| 137 |
+
between output lines. Default '\n'.
|
| 138 |
+
|
| 139 |
+
cte_type -- Type of allowed content transfer encodings
|
| 140 |
+
|
| 141 |
+
7bit -- ASCII only
|
| 142 |
+
8bit -- Content-Transfer-Encoding: 8bit is allowed
|
| 143 |
+
|
| 144 |
+
Default: 8bit. Also controls the disposition of
|
| 145 |
+
(RFC invalid) binary data in headers; see the
|
| 146 |
+
documentation of the binary_fold method.
|
| 147 |
+
|
| 148 |
+
max_line_length -- maximum length of lines, excluding 'linesep',
|
| 149 |
+
during serialization. None or 0 means no line
|
| 150 |
+
wrapping is done. Default is 78.
|
| 151 |
+
|
| 152 |
+
mangle_from_ -- a flag that, when True escapes From_ lines in the
|
| 153 |
+
body of the message by putting a `>' in front of
|
| 154 |
+
them. This is used when the message is being
|
| 155 |
+
serialized by a generator. Default: True.
|
| 156 |
+
|
| 157 |
+
message_factory -- the class to use to create new message objects.
|
| 158 |
+
If the value is None, the default is Message.
|
| 159 |
+
|
| 160 |
+
verify_generated_headers
|
| 161 |
+
-- if true, the generator verifies that each header
|
| 162 |
+
they are properly folded, so that a parser won't
|
| 163 |
+
treat it as multiple headers, start-of-body, or
|
| 164 |
+
part of another header.
|
| 165 |
+
This is a check against custom Header & fold()
|
| 166 |
+
implementations.
|
| 167 |
+
"""
|
| 168 |
+
|
| 169 |
+
raise_on_defect = False
|
| 170 |
+
linesep = '\n'
|
| 171 |
+
cte_type = '8bit'
|
| 172 |
+
max_line_length = 78
|
| 173 |
+
mangle_from_ = False
|
| 174 |
+
message_factory = None
|
| 175 |
+
verify_generated_headers = True
|
| 176 |
+
|
| 177 |
+
def handle_defect(self, obj, defect):
|
| 178 |
+
"""Based on policy, either raise defect or call register_defect.
|
| 179 |
+
|
| 180 |
+
handle_defect(obj, defect)
|
| 181 |
+
|
| 182 |
+
defect should be a Defect subclass, but in any case must be an
|
| 183 |
+
Exception subclass. obj is the object on which the defect should be
|
| 184 |
+
registered if it is not raised. If the raise_on_defect is True, the
|
| 185 |
+
defect is raised as an error, otherwise the object and the defect are
|
| 186 |
+
passed to register_defect.
|
| 187 |
+
|
| 188 |
+
This method is intended to be called by parsers that discover defects.
|
| 189 |
+
The email package parsers always call it with Defect instances.
|
| 190 |
+
|
| 191 |
+
"""
|
| 192 |
+
if self.raise_on_defect:
|
| 193 |
+
raise defect
|
| 194 |
+
self.register_defect(obj, defect)
|
| 195 |
+
|
| 196 |
+
def register_defect(self, obj, defect):
|
| 197 |
+
"""Record 'defect' on 'obj'.
|
| 198 |
+
|
| 199 |
+
Called by handle_defect if raise_on_defect is False. This method is
|
| 200 |
+
part of the Policy API so that Policy subclasses can implement custom
|
| 201 |
+
defect handling. The default implementation calls the append method of
|
| 202 |
+
the defects attribute of obj. The objects used by the email package by
|
| 203 |
+
default that get passed to this method will always have a defects
|
| 204 |
+
attribute with an append method.
|
| 205 |
+
|
| 206 |
+
"""
|
| 207 |
+
obj.defects.append(defect)
|
| 208 |
+
|
| 209 |
+
def header_max_count(self, name):
|
| 210 |
+
"""Return the maximum allowed number of headers named 'name'.
|
| 211 |
+
|
| 212 |
+
Called when a header is added to a Message object. If the returned
|
| 213 |
+
value is not 0 or None, and there are already a number of headers with
|
| 214 |
+
the name 'name' equal to the value returned, a ValueError is raised.
|
| 215 |
+
|
| 216 |
+
Because the default behavior of Message's __setitem__ is to append the
|
| 217 |
+
value to the list of headers, it is easy to create duplicate headers
|
| 218 |
+
without realizing it. This method allows certain headers to be limited
|
| 219 |
+
in the number of instances of that header that may be added to a
|
| 220 |
+
Message programmatically. (The limit is not observed by the parser,
|
| 221 |
+
which will faithfully produce as many headers as exist in the message
|
| 222 |
+
being parsed.)
|
| 223 |
+
|
| 224 |
+
The default implementation returns None for all header names.
|
| 225 |
+
"""
|
| 226 |
+
return None
|
| 227 |
+
|
| 228 |
+
@abc.abstractmethod
|
| 229 |
+
def header_source_parse(self, sourcelines):
|
| 230 |
+
"""Given a list of linesep terminated strings constituting the lines of
|
| 231 |
+
a single header, return the (name, value) tuple that should be stored
|
| 232 |
+
in the model. The input lines should retain their terminating linesep
|
| 233 |
+
characters. The lines passed in by the email package may contain
|
| 234 |
+
surrogateescaped binary data.
|
| 235 |
+
"""
|
| 236 |
+
raise NotImplementedError
|
| 237 |
+
|
| 238 |
+
@abc.abstractmethod
|
| 239 |
+
def header_store_parse(self, name, value):
|
| 240 |
+
"""Given the header name and the value provided by the application
|
| 241 |
+
program, return the (name, value) that should be stored in the model.
|
| 242 |
+
"""
|
| 243 |
+
raise NotImplementedError
|
| 244 |
+
|
| 245 |
+
@abc.abstractmethod
|
| 246 |
+
def header_fetch_parse(self, name, value):
|
| 247 |
+
"""Given the header name and the value from the model, return the value
|
| 248 |
+
to be returned to the application program that is requesting that
|
| 249 |
+
header. The value passed in by the email package may contain
|
| 250 |
+
surrogateescaped binary data if the lines were parsed by a BytesParser.
|
| 251 |
+
The returned value should not contain any surrogateescaped data.
|
| 252 |
+
|
| 253 |
+
"""
|
| 254 |
+
raise NotImplementedError
|
| 255 |
+
|
| 256 |
+
@abc.abstractmethod
|
| 257 |
+
def fold(self, name, value):
|
| 258 |
+
"""Given the header name and the value from the model, return a string
|
| 259 |
+
containing linesep characters that implement the folding of the header
|
| 260 |
+
according to the policy controls. The value passed in by the email
|
| 261 |
+
package may contain surrogateescaped binary data if the lines were
|
| 262 |
+
parsed by a BytesParser. The returned value should not contain any
|
| 263 |
+
surrogateescaped data.
|
| 264 |
+
|
| 265 |
+
"""
|
| 266 |
+
raise NotImplementedError
|
| 267 |
+
|
| 268 |
+
@abc.abstractmethod
|
| 269 |
+
def fold_binary(self, name, value):
|
| 270 |
+
"""Given the header name and the value from the model, return binary
|
| 271 |
+
data containing linesep characters that implement the folding of the
|
| 272 |
+
header according to the policy controls. The value passed in by the
|
| 273 |
+
email package may contain surrogateescaped binary data.
|
| 274 |
+
|
| 275 |
+
"""
|
| 276 |
+
raise NotImplementedError
|
| 277 |
+
|
| 278 |
+
|
| 279 |
+
@_extend_docstrings
|
| 280 |
+
class Compat32(Policy):
|
| 281 |
+
|
| 282 |
+
"""+
|
| 283 |
+
This particular policy is the backward compatibility Policy. It
|
| 284 |
+
replicates the behavior of the email package version 5.1.
|
| 285 |
+
"""
|
| 286 |
+
|
| 287 |
+
mangle_from_ = True
|
| 288 |
+
|
| 289 |
+
def _sanitize_header(self, name, value):
|
| 290 |
+
# If the header value contains surrogates, return a Header using
|
| 291 |
+
# the unknown-8bit charset to encode the bytes as encoded words.
|
| 292 |
+
if not isinstance(value, str):
|
| 293 |
+
# Assume it is already a header object
|
| 294 |
+
return value
|
| 295 |
+
if _has_surrogates(value):
|
| 296 |
+
return header.Header(value, charset=_charset.UNKNOWN8BIT,
|
| 297 |
+
header_name=name)
|
| 298 |
+
else:
|
| 299 |
+
return value
|
| 300 |
+
|
| 301 |
+
def header_source_parse(self, sourcelines):
|
| 302 |
+
"""+
|
| 303 |
+
The name is parsed as everything up to the ':' and returned unmodified.
|
| 304 |
+
The value is determined by stripping leading whitespace off the
|
| 305 |
+
remainder of the first line, joining all subsequent lines together, and
|
| 306 |
+
stripping any trailing carriage return or linefeed characters.
|
| 307 |
+
|
| 308 |
+
"""
|
| 309 |
+
name, value = sourcelines[0].split(':', 1)
|
| 310 |
+
value = value.lstrip(' \t') + ''.join(sourcelines[1:])
|
| 311 |
+
return (name, value.rstrip('\r\n'))
|
| 312 |
+
|
| 313 |
+
def header_store_parse(self, name, value):
|
| 314 |
+
"""+
|
| 315 |
+
The name and value are returned unmodified.
|
| 316 |
+
"""
|
| 317 |
+
return (name, value)
|
| 318 |
+
|
| 319 |
+
def header_fetch_parse(self, name, value):
|
| 320 |
+
"""+
|
| 321 |
+
If the value contains binary data, it is converted into a Header object
|
| 322 |
+
using the unknown-8bit charset. Otherwise it is returned unmodified.
|
| 323 |
+
"""
|
| 324 |
+
return self._sanitize_header(name, value)
|
| 325 |
+
|
| 326 |
+
def fold(self, name, value):
|
| 327 |
+
"""+
|
| 328 |
+
Headers are folded using the Header folding algorithm, which preserves
|
| 329 |
+
existing line breaks in the value, and wraps each resulting line to the
|
| 330 |
+
max_line_length. Non-ASCII binary data are CTE encoded using the
|
| 331 |
+
unknown-8bit charset.
|
| 332 |
+
|
| 333 |
+
"""
|
| 334 |
+
return self._fold(name, value, sanitize=True)
|
| 335 |
+
|
| 336 |
+
def fold_binary(self, name, value):
|
| 337 |
+
"""+
|
| 338 |
+
Headers are folded using the Header folding algorithm, which preserves
|
| 339 |
+
existing line breaks in the value, and wraps each resulting line to the
|
| 340 |
+
max_line_length. If cte_type is 7bit, non-ascii binary data is CTE
|
| 341 |
+
encoded using the unknown-8bit charset. Otherwise the original source
|
| 342 |
+
header is used, with its existing line breaks and/or binary data.
|
| 343 |
+
|
| 344 |
+
"""
|
| 345 |
+
folded = self._fold(name, value, sanitize=self.cte_type=='7bit')
|
| 346 |
+
return folded.encode('ascii', 'surrogateescape')
|
| 347 |
+
|
| 348 |
+
def _fold(self, name, value, sanitize):
|
| 349 |
+
parts = []
|
| 350 |
+
parts.append('%s: ' % name)
|
| 351 |
+
if isinstance(value, str):
|
| 352 |
+
if _has_surrogates(value):
|
| 353 |
+
if sanitize:
|
| 354 |
+
h = header.Header(value,
|
| 355 |
+
charset=_charset.UNKNOWN8BIT,
|
| 356 |
+
header_name=name)
|
| 357 |
+
else:
|
| 358 |
+
# If we have raw 8bit data in a byte string, we have no idea
|
| 359 |
+
# what the encoding is. There is no safe way to split this
|
| 360 |
+
# string. If it's ascii-subset, then we could do a normal
|
| 361 |
+
# ascii split, but if it's multibyte then we could break the
|
| 362 |
+
# string. There's no way to know so the least harm seems to
|
| 363 |
+
# be to not split the string and risk it being too long.
|
| 364 |
+
parts.append(value)
|
| 365 |
+
h = None
|
| 366 |
+
else:
|
| 367 |
+
h = header.Header(value, header_name=name)
|
| 368 |
+
else:
|
| 369 |
+
# Assume it is a Header-like object.
|
| 370 |
+
h = value
|
| 371 |
+
if h is not None:
|
| 372 |
+
# The Header class interprets a value of None for maxlinelen as the
|
| 373 |
+
# default value of 78, as recommended by RFC 2822.
|
| 374 |
+
maxlinelen = 0
|
| 375 |
+
if self.max_line_length is not None:
|
| 376 |
+
maxlinelen = self.max_line_length
|
| 377 |
+
parts.append(h.encode(linesep=self.linesep, maxlinelen=maxlinelen))
|
| 378 |
+
parts.append(self.linesep)
|
| 379 |
+
return ''.join(parts)
|
| 380 |
+
|
| 381 |
+
|
| 382 |
+
compat32 = Compat32()
|