Add files using upload-large-folder tool
Browse filesThis view is limited to 50 files because it contains too many changes.
See raw diff
- .gitattributes +3 -0
- janus/lib/python3.10/__pycache__/_osx_support.cpython-310.pyc +0 -0
- janus/lib/python3.10/__pycache__/_sitebuiltins.cpython-310.pyc +0 -0
- janus/lib/python3.10/__pycache__/binhex.cpython-310.pyc +0 -0
- janus/lib/python3.10/__pycache__/cProfile.cpython-310.pyc +0 -0
- janus/lib/python3.10/__pycache__/chunk.cpython-310.pyc +0 -0
- janus/lib/python3.10/__pycache__/compileall.cpython-310.pyc +0 -0
- janus/lib/python3.10/__pycache__/dataclasses.cpython-310.pyc +0 -0
- janus/lib/python3.10/__pycache__/enum.cpython-310.pyc +0 -0
- janus/lib/python3.10/__pycache__/functools.cpython-310.pyc +0 -0
- janus/lib/python3.10/__pycache__/getpass.cpython-310.pyc +0 -0
- janus/lib/python3.10/__pycache__/imp.cpython-310.pyc +0 -0
- janus/lib/python3.10/__pycache__/io.cpython-310.pyc +0 -0
- janus/lib/python3.10/__pycache__/keyword.cpython-310.pyc +0 -0
- janus/lib/python3.10/__pycache__/locale.cpython-310.pyc +0 -0
- janus/lib/python3.10/__pycache__/optparse.cpython-310.pyc +0 -0
- janus/lib/python3.10/__pycache__/pathlib.cpython-310.pyc +0 -0
- janus/lib/python3.10/__pycache__/pdb.cpython-310.pyc +0 -0
- janus/lib/python3.10/__pycache__/pickle.cpython-310.pyc +0 -0
- janus/lib/python3.10/__pycache__/platform.cpython-310.pyc +0 -0
- janus/lib/python3.10/__pycache__/py_compile.cpython-310.pyc +0 -0
- janus/lib/python3.10/__pycache__/pyclbr.cpython-310.pyc +0 -0
- janus/lib/python3.10/__pycache__/quopri.cpython-310.pyc +0 -0
- janus/lib/python3.10/__pycache__/reprlib.cpython-310.pyc +0 -0
- janus/lib/python3.10/__pycache__/selectors.cpython-310.pyc +0 -0
- janus/lib/python3.10/__pycache__/shlex.cpython-310.pyc +0 -0
- janus/lib/python3.10/__pycache__/shutil.cpython-310.pyc +0 -0
- janus/lib/python3.10/__pycache__/smtpd.cpython-310.pyc +0 -0
- janus/lib/python3.10/__pycache__/ssl.cpython-310.pyc +0 -0
- janus/lib/python3.10/__pycache__/string.cpython-310.pyc +0 -0
- janus/lib/python3.10/__pycache__/tempfile.cpython-310.pyc +0 -0
- janus/lib/python3.10/__pycache__/tracemalloc.cpython-310.pyc +0 -0
- janus/lib/python3.10/__pycache__/turtle.cpython-310.pyc +3 -0
- janus/lib/python3.10/__pycache__/uu.cpython-310.pyc +0 -0
- janus/lib/python3.10/__pycache__/weakref.cpython-310.pyc +0 -0
- janus/lib/python3.10/__pycache__/xdrlib.cpython-310.pyc +0 -0
- janus/lib/python3.10/config-3.10-x86_64-linux-gnu/config.c.in +67 -0
- janus/lib/python3.10/email/__init__.py +62 -0
- janus/lib/python3.10/email/__pycache__/_header_value_parser.cpython-310.pyc +0 -0
- janus/lib/python3.10/email/__pycache__/_parseaddr.cpython-310.pyc +0 -0
- janus/lib/python3.10/email/__pycache__/charset.cpython-310.pyc +0 -0
- janus/lib/python3.10/email/__pycache__/encoders.cpython-310.pyc +0 -0
- janus/lib/python3.10/email/__pycache__/errors.cpython-310.pyc +0 -0
- janus/lib/python3.10/email/__pycache__/iterators.cpython-310.pyc +0 -0
- janus/lib/python3.10/email/__pycache__/message.cpython-310.pyc +0 -0
- janus/lib/python3.10/email/_encoded_words.py +233 -0
- janus/lib/python3.10/email/_header_value_parser.py +0 -0
- janus/lib/python3.10/email/_parseaddr.py +557 -0
- janus/lib/python3.10/email/_policybase.py +382 -0
- janus/lib/python3.10/email/architecture.rst +216 -0
.gitattributes
CHANGED
|
@@ -517,3 +517,6 @@ janus/lib/python3.10/__pycache__/_pydecimal.cpython-310.pyc filter=lfs diff=lfs
|
|
| 517 |
janus/lib/python3.10/site-packages/numpy/random/_mt19937.cpython-310-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
|
| 518 |
janus/lib/python3.10/site-packages/numpy/random/_philox.cpython-310-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
|
| 519 |
janus/lib/python3.10/site-packages/numpy/_core/__pycache__/_add_newdocs.cpython-310.pyc filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
|
|
|
|
|
|
| 517 |
janus/lib/python3.10/site-packages/numpy/random/_mt19937.cpython-310-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
|
| 518 |
janus/lib/python3.10/site-packages/numpy/random/_philox.cpython-310-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
|
| 519 |
janus/lib/python3.10/site-packages/numpy/_core/__pycache__/_add_newdocs.cpython-310.pyc filter=lfs diff=lfs merge=lfs -text
|
| 520 |
+
janus/lib/python3.10/__pycache__/turtle.cpython-310.pyc filter=lfs diff=lfs merge=lfs -text
|
| 521 |
+
janus/lib/python3.10/site-packages/numpy/fft/_pocketfft_umath.cpython-310-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
|
| 522 |
+
janus/lib/python3.10/site-packages/numpy/ma/tests/__pycache__/test_core.cpython-310.pyc filter=lfs diff=lfs merge=lfs -text
|
janus/lib/python3.10/__pycache__/_osx_support.cpython-310.pyc
ADDED
|
Binary file (11.8 kB). View file
|
|
|
janus/lib/python3.10/__pycache__/_sitebuiltins.cpython-310.pyc
ADDED
|
Binary file (3.54 kB). View file
|
|
|
janus/lib/python3.10/__pycache__/binhex.cpython-310.pyc
ADDED
|
Binary file (12.9 kB). View file
|
|
|
janus/lib/python3.10/__pycache__/cProfile.cpython-310.pyc
ADDED
|
Binary file (5.11 kB). View file
|
|
|
janus/lib/python3.10/__pycache__/chunk.cpython-310.pyc
ADDED
|
Binary file (5.11 kB). View file
|
|
|
janus/lib/python3.10/__pycache__/compileall.cpython-310.pyc
ADDED
|
Binary file (12.7 kB). View file
|
|
|
janus/lib/python3.10/__pycache__/dataclasses.cpython-310.pyc
ADDED
|
Binary file (26.8 kB). View file
|
|
|
janus/lib/python3.10/__pycache__/enum.cpython-310.pyc
ADDED
|
Binary file (26.3 kB). View file
|
|
|
janus/lib/python3.10/__pycache__/functools.cpython-310.pyc
ADDED
|
Binary file (28.6 kB). View file
|
|
|
janus/lib/python3.10/__pycache__/getpass.cpython-310.pyc
ADDED
|
Binary file (4.21 kB). View file
|
|
|
janus/lib/python3.10/__pycache__/imp.cpython-310.pyc
ADDED
|
Binary file (9.78 kB). View file
|
|
|
janus/lib/python3.10/__pycache__/io.cpython-310.pyc
ADDED
|
Binary file (3.92 kB). View file
|
|
|
janus/lib/python3.10/__pycache__/keyword.cpython-310.pyc
ADDED
|
Binary file (1.18 kB). View file
|
|
|
janus/lib/python3.10/__pycache__/locale.cpython-310.pyc
ADDED
|
Binary file (46.4 kB). View file
|
|
|
janus/lib/python3.10/__pycache__/optparse.cpython-310.pyc
ADDED
|
Binary file (48 kB). View file
|
|
|
janus/lib/python3.10/__pycache__/pathlib.cpython-310.pyc
ADDED
|
Binary file (42.3 kB). View file
|
|
|
janus/lib/python3.10/__pycache__/pdb.cpython-310.pyc
ADDED
|
Binary file (47.4 kB). View file
|
|
|
janus/lib/python3.10/__pycache__/pickle.cpython-310.pyc
ADDED
|
Binary file (46.9 kB). View file
|
|
|
janus/lib/python3.10/__pycache__/platform.cpython-310.pyc
ADDED
|
Binary file (27.7 kB). View file
|
|
|
janus/lib/python3.10/__pycache__/py_compile.cpython-310.pyc
ADDED
|
Binary file (7.57 kB). View file
|
|
|
janus/lib/python3.10/__pycache__/pyclbr.cpython-310.pyc
ADDED
|
Binary file (10 kB). View file
|
|
|
janus/lib/python3.10/__pycache__/quopri.cpython-310.pyc
ADDED
|
Binary file (6.05 kB). View file
|
|
|
janus/lib/python3.10/__pycache__/reprlib.cpython-310.pyc
ADDED
|
Binary file (5.5 kB). View file
|
|
|
janus/lib/python3.10/__pycache__/selectors.cpython-310.pyc
ADDED
|
Binary file (17.4 kB). View file
|
|
|
janus/lib/python3.10/__pycache__/shlex.cpython-310.pyc
ADDED
|
Binary file (8.04 kB). View file
|
|
|
janus/lib/python3.10/__pycache__/shutil.cpython-310.pyc
ADDED
|
Binary file (38.5 kB). View file
|
|
|
janus/lib/python3.10/__pycache__/smtpd.cpython-310.pyc
ADDED
|
Binary file (26.4 kB). View file
|
|
|
janus/lib/python3.10/__pycache__/ssl.cpython-310.pyc
ADDED
|
Binary file (45.5 kB). View file
|
|
|
janus/lib/python3.10/__pycache__/string.cpython-310.pyc
ADDED
|
Binary file (7.36 kB). View file
|
|
|
janus/lib/python3.10/__pycache__/tempfile.cpython-310.pyc
ADDED
|
Binary file (24.6 kB). View file
|
|
|
janus/lib/python3.10/__pycache__/tracemalloc.cpython-310.pyc
ADDED
|
Binary file (17.8 kB). View file
|
|
|
janus/lib/python3.10/__pycache__/turtle.cpython-310.pyc
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:3e0a3de6e5bcb4263511830455a4bbd4d4628106d06d391cf31df663f8de6adf
|
| 3 |
+
size 129111
|
janus/lib/python3.10/__pycache__/uu.cpython-310.pyc
ADDED
|
Binary file (4.12 kB). View file
|
|
|
janus/lib/python3.10/__pycache__/weakref.cpython-310.pyc
ADDED
|
Binary file (20.6 kB). View file
|
|
|
janus/lib/python3.10/__pycache__/xdrlib.cpython-310.pyc
ADDED
|
Binary file (7.88 kB). View file
|
|
|
janus/lib/python3.10/config-3.10-x86_64-linux-gnu/config.c.in
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/* -*- C -*- ***********************************************
|
| 2 |
+
Copyright (c) 2000, BeOpen.com.
|
| 3 |
+
Copyright (c) 1995-2000, Corporation for National Research Initiatives.
|
| 4 |
+
Copyright (c) 1990-1995, Stichting Mathematisch Centrum.
|
| 5 |
+
All rights reserved.
|
| 6 |
+
|
| 7 |
+
See the file "Misc/COPYRIGHT" for information on usage and
|
| 8 |
+
redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES.
|
| 9 |
+
******************************************************************/
|
| 10 |
+
|
| 11 |
+
/* Module configuration */
|
| 12 |
+
|
| 13 |
+
/* !!! !!! !!! This file is edited by the makesetup script !!! !!! !!! */
|
| 14 |
+
|
| 15 |
+
/* This file contains the table of built-in modules.
|
| 16 |
+
See create_builtin() in import.c. */
|
| 17 |
+
|
| 18 |
+
#include "Python.h"
|
| 19 |
+
|
| 20 |
+
#ifdef __cplusplus
|
| 21 |
+
extern "C" {
|
| 22 |
+
#endif
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
/* -- ADDMODULE MARKER 1 -- */
|
| 26 |
+
|
| 27 |
+
extern PyObject* PyMarshal_Init(void);
|
| 28 |
+
extern PyObject* PyInit__imp(void);
|
| 29 |
+
extern PyObject* PyInit_gc(void);
|
| 30 |
+
extern PyObject* PyInit__ast(void);
|
| 31 |
+
extern PyObject* _PyWarnings_Init(void);
|
| 32 |
+
extern PyObject* PyInit__string(void);
|
| 33 |
+
|
| 34 |
+
struct _inittab _PyImport_Inittab[] = {
|
| 35 |
+
|
| 36 |
+
/* -- ADDMODULE MARKER 2 -- */
|
| 37 |
+
|
| 38 |
+
/* This module lives in marshal.c */
|
| 39 |
+
{"marshal", PyMarshal_Init},
|
| 40 |
+
|
| 41 |
+
/* This lives in import.c */
|
| 42 |
+
{"_imp", PyInit__imp},
|
| 43 |
+
|
| 44 |
+
/* This lives in Python/Python-ast.c */
|
| 45 |
+
{"_ast", PyInit__ast},
|
| 46 |
+
|
| 47 |
+
/* These entries are here for sys.builtin_module_names */
|
| 48 |
+
{"builtins", NULL},
|
| 49 |
+
{"sys", NULL},
|
| 50 |
+
|
| 51 |
+
/* This lives in gcmodule.c */
|
| 52 |
+
{"gc", PyInit_gc},
|
| 53 |
+
|
| 54 |
+
/* This lives in _warnings.c */
|
| 55 |
+
{"_warnings", _PyWarnings_Init},
|
| 56 |
+
|
| 57 |
+
/* This lives in Objects/unicodeobject.c */
|
| 58 |
+
{"_string", PyInit__string},
|
| 59 |
+
|
| 60 |
+
/* Sentinel */
|
| 61 |
+
{0, 0}
|
| 62 |
+
};
|
| 63 |
+
|
| 64 |
+
|
| 65 |
+
#ifdef __cplusplus
|
| 66 |
+
}
|
| 67 |
+
#endif
|
janus/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 protected]
|
| 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)
|
janus/lib/python3.10/email/__pycache__/_header_value_parser.cpython-310.pyc
ADDED
|
Binary file (78.1 kB). View file
|
|
|
janus/lib/python3.10/email/__pycache__/_parseaddr.cpython-310.pyc
ADDED
|
Binary file (12.8 kB). View file
|
|
|
janus/lib/python3.10/email/__pycache__/charset.cpython-310.pyc
ADDED
|
Binary file (11.8 kB). View file
|
|
|
janus/lib/python3.10/email/__pycache__/encoders.cpython-310.pyc
ADDED
|
Binary file (1.62 kB). View file
|
|
|
janus/lib/python3.10/email/__pycache__/errors.cpython-310.pyc
ADDED
|
Binary file (6.1 kB). View file
|
|
|
janus/lib/python3.10/email/__pycache__/iterators.cpython-310.pyc
ADDED
|
Binary file (2.22 kB). View file
|
|
|
janus/lib/python3.10/email/__pycache__/message.cpython-310.pyc
ADDED
|
Binary file (38.1 kB). View file
|
|
|
janus/lib/python3.10/email/_encoded_words.py
ADDED
|
@@ -0,0 +1,233 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
| 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)
|
janus/lib/python3.10/email/_header_value_parser.py
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
janus/lib/python3.10/email/_parseaddr.py
ADDED
|
@@ -0,0 +1,557 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Copyright (C) 2002-2007 Python Software Foundation
|
| 2 |
+
# Contact: [email protected]
|
| 3 |
+
|
| 4 |
+
"""Email address parsing code.
|
| 5 |
+
|
| 6 |
+
Lifted directly from rfc822.py. This should eventually be rewritten.
|
| 7 |
+
"""
|
| 8 |
+
|
| 9 |
+
__all__ = [
|
| 10 |
+
'mktime_tz',
|
| 11 |
+
'parsedate',
|
| 12 |
+
'parsedate_tz',
|
| 13 |
+
'quote',
|
| 14 |
+
]
|
| 15 |
+
|
| 16 |
+
import time, calendar
|
| 17 |
+
|
| 18 |
+
SPACE = ' '
|
| 19 |
+
EMPTYSTRING = ''
|
| 20 |
+
COMMASPACE = ', '
|
| 21 |
+
|
| 22 |
+
# Parse a date field
|
| 23 |
+
_monthnames = ['jan', 'feb', 'mar', 'apr', 'may', 'jun', 'jul',
|
| 24 |
+
'aug', 'sep', 'oct', 'nov', 'dec',
|
| 25 |
+
'january', 'february', 'march', 'april', 'may', 'june', 'july',
|
| 26 |
+
'august', 'september', 'october', 'november', 'december']
|
| 27 |
+
|
| 28 |
+
_daynames = ['mon', 'tue', 'wed', 'thu', 'fri', 'sat', 'sun']
|
| 29 |
+
|
| 30 |
+
# The timezone table does not include the military time zones defined
|
| 31 |
+
# in RFC822, other than Z. According to RFC1123, the description in
|
| 32 |
+
# RFC822 gets the signs wrong, so we can't rely on any such time
|
| 33 |
+
# zones. RFC1123 recommends that numeric timezone indicators be used
|
| 34 |
+
# instead of timezone names.
|
| 35 |
+
|
| 36 |
+
_timezones = {'UT':0, 'UTC':0, 'GMT':0, 'Z':0,
|
| 37 |
+
'AST': -400, 'ADT': -300, # Atlantic (used in Canada)
|
| 38 |
+
'EST': -500, 'EDT': -400, # Eastern
|
| 39 |
+
'CST': -600, 'CDT': -500, # Central
|
| 40 |
+
'MST': -700, 'MDT': -600, # Mountain
|
| 41 |
+
'PST': -800, 'PDT': -700 # Pacific
|
| 42 |
+
}
|
| 43 |
+
|
| 44 |
+
|
| 45 |
+
def parsedate_tz(data):
|
| 46 |
+
"""Convert a date string to a time tuple.
|
| 47 |
+
|
| 48 |
+
Accounts for military timezones.
|
| 49 |
+
"""
|
| 50 |
+
res = _parsedate_tz(data)
|
| 51 |
+
if not res:
|
| 52 |
+
return
|
| 53 |
+
if res[9] is None:
|
| 54 |
+
res[9] = 0
|
| 55 |
+
return tuple(res)
|
| 56 |
+
|
| 57 |
+
def _parsedate_tz(data):
|
| 58 |
+
"""Convert date to extended time tuple.
|
| 59 |
+
|
| 60 |
+
The last (additional) element is the time zone offset in seconds, except if
|
| 61 |
+
the timezone was specified as -0000. In that case the last element is
|
| 62 |
+
None. This indicates a UTC timestamp that explicitly declaims knowledge of
|
| 63 |
+
the source timezone, as opposed to a +0000 timestamp that indicates the
|
| 64 |
+
source timezone really was UTC.
|
| 65 |
+
|
| 66 |
+
"""
|
| 67 |
+
if not data:
|
| 68 |
+
return None
|
| 69 |
+
data = data.split()
|
| 70 |
+
if not data: # This happens for whitespace-only input.
|
| 71 |
+
return None
|
| 72 |
+
# The FWS after the comma after the day-of-week is optional, so search and
|
| 73 |
+
# adjust for this.
|
| 74 |
+
if data[0].endswith(',') or data[0].lower() in _daynames:
|
| 75 |
+
# There's a dayname here. Skip it
|
| 76 |
+
del data[0]
|
| 77 |
+
else:
|
| 78 |
+
i = data[0].rfind(',')
|
| 79 |
+
if i >= 0:
|
| 80 |
+
data[0] = data[0][i+1:]
|
| 81 |
+
if len(data) == 3: # RFC 850 date, deprecated
|
| 82 |
+
stuff = data[0].split('-')
|
| 83 |
+
if len(stuff) == 3:
|
| 84 |
+
data = stuff + data[1:]
|
| 85 |
+
if len(data) == 4:
|
| 86 |
+
s = data[3]
|
| 87 |
+
i = s.find('+')
|
| 88 |
+
if i == -1:
|
| 89 |
+
i = s.find('-')
|
| 90 |
+
if i > 0:
|
| 91 |
+
data[3:] = [s[:i], s[i:]]
|
| 92 |
+
else:
|
| 93 |
+
data.append('') # Dummy tz
|
| 94 |
+
if len(data) < 5:
|
| 95 |
+
return None
|
| 96 |
+
data = data[:5]
|
| 97 |
+
[dd, mm, yy, tm, tz] = data
|
| 98 |
+
if not (dd and mm and yy):
|
| 99 |
+
return None
|
| 100 |
+
mm = mm.lower()
|
| 101 |
+
if mm not in _monthnames:
|
| 102 |
+
dd, mm = mm, dd.lower()
|
| 103 |
+
if mm not in _monthnames:
|
| 104 |
+
return None
|
| 105 |
+
mm = _monthnames.index(mm) + 1
|
| 106 |
+
if mm > 12:
|
| 107 |
+
mm -= 12
|
| 108 |
+
if dd[-1] == ',':
|
| 109 |
+
dd = dd[:-1]
|
| 110 |
+
i = yy.find(':')
|
| 111 |
+
if i > 0:
|
| 112 |
+
yy, tm = tm, yy
|
| 113 |
+
if yy[-1] == ',':
|
| 114 |
+
yy = yy[:-1]
|
| 115 |
+
if not yy:
|
| 116 |
+
return None
|
| 117 |
+
if not yy[0].isdigit():
|
| 118 |
+
yy, tz = tz, yy
|
| 119 |
+
if tm[-1] == ',':
|
| 120 |
+
tm = tm[:-1]
|
| 121 |
+
tm = tm.split(':')
|
| 122 |
+
if len(tm) == 2:
|
| 123 |
+
[thh, tmm] = tm
|
| 124 |
+
tss = '0'
|
| 125 |
+
elif len(tm) == 3:
|
| 126 |
+
[thh, tmm, tss] = tm
|
| 127 |
+
elif len(tm) == 1 and '.' in tm[0]:
|
| 128 |
+
# Some non-compliant MUAs use '.' to separate time elements.
|
| 129 |
+
tm = tm[0].split('.')
|
| 130 |
+
if len(tm) == 2:
|
| 131 |
+
[thh, tmm] = tm
|
| 132 |
+
tss = 0
|
| 133 |
+
elif len(tm) == 3:
|
| 134 |
+
[thh, tmm, tss] = tm
|
| 135 |
+
else:
|
| 136 |
+
return None
|
| 137 |
+
else:
|
| 138 |
+
return None
|
| 139 |
+
try:
|
| 140 |
+
yy = int(yy)
|
| 141 |
+
dd = int(dd)
|
| 142 |
+
thh = int(thh)
|
| 143 |
+
tmm = int(tmm)
|
| 144 |
+
tss = int(tss)
|
| 145 |
+
except ValueError:
|
| 146 |
+
return None
|
| 147 |
+
# Check for a yy specified in two-digit format, then convert it to the
|
| 148 |
+
# appropriate four-digit format, according to the POSIX standard. RFC 822
|
| 149 |
+
# calls for a two-digit yy, but RFC 2822 (which obsoletes RFC 822)
|
| 150 |
+
# mandates a 4-digit yy. For more information, see the documentation for
|
| 151 |
+
# the time module.
|
| 152 |
+
if yy < 100:
|
| 153 |
+
# The year is between 1969 and 1999 (inclusive).
|
| 154 |
+
if yy > 68:
|
| 155 |
+
yy += 1900
|
| 156 |
+
# The year is between 2000 and 2068 (inclusive).
|
| 157 |
+
else:
|
| 158 |
+
yy += 2000
|
| 159 |
+
tzoffset = None
|
| 160 |
+
tz = tz.upper()
|
| 161 |
+
if tz in _timezones:
|
| 162 |
+
tzoffset = _timezones[tz]
|
| 163 |
+
else:
|
| 164 |
+
try:
|
| 165 |
+
tzoffset = int(tz)
|
| 166 |
+
except ValueError:
|
| 167 |
+
pass
|
| 168 |
+
if tzoffset==0 and tz.startswith('-'):
|
| 169 |
+
tzoffset = None
|
| 170 |
+
# Convert a timezone offset into seconds ; -0500 -> -18000
|
| 171 |
+
if tzoffset:
|
| 172 |
+
if tzoffset < 0:
|
| 173 |
+
tzsign = -1
|
| 174 |
+
tzoffset = -tzoffset
|
| 175 |
+
else:
|
| 176 |
+
tzsign = 1
|
| 177 |
+
tzoffset = tzsign * ( (tzoffset//100)*3600 + (tzoffset % 100)*60)
|
| 178 |
+
# Daylight Saving Time flag is set to -1, since DST is unknown.
|
| 179 |
+
return [yy, mm, dd, thh, tmm, tss, 0, 1, -1, tzoffset]
|
| 180 |
+
|
| 181 |
+
|
| 182 |
+
def parsedate(data):
|
| 183 |
+
"""Convert a time string to a time tuple."""
|
| 184 |
+
t = parsedate_tz(data)
|
| 185 |
+
if isinstance(t, tuple):
|
| 186 |
+
return t[:9]
|
| 187 |
+
else:
|
| 188 |
+
return t
|
| 189 |
+
|
| 190 |
+
|
| 191 |
+
def mktime_tz(data):
|
| 192 |
+
"""Turn a 10-tuple as returned by parsedate_tz() into a POSIX timestamp."""
|
| 193 |
+
if data[9] is None:
|
| 194 |
+
# No zone info, so localtime is better assumption than GMT
|
| 195 |
+
return time.mktime(data[:8] + (-1,))
|
| 196 |
+
else:
|
| 197 |
+
t = calendar.timegm(data)
|
| 198 |
+
return t - data[9]
|
| 199 |
+
|
| 200 |
+
|
| 201 |
+
def quote(str):
|
| 202 |
+
"""Prepare string to be used in a quoted string.
|
| 203 |
+
|
| 204 |
+
Turns backslash and double quote characters into quoted pairs. These
|
| 205 |
+
are the only characters that need to be quoted inside a quoted string.
|
| 206 |
+
Does not add the surrounding double quotes.
|
| 207 |
+
"""
|
| 208 |
+
return str.replace('\\', '\\\\').replace('"', '\\"')
|
| 209 |
+
|
| 210 |
+
|
| 211 |
+
class AddrlistClass:
|
| 212 |
+
"""Address parser class by Ben Escoto.
|
| 213 |
+
|
| 214 |
+
To understand what this class does, it helps to have a copy of RFC 2822 in
|
| 215 |
+
front of you.
|
| 216 |
+
|
| 217 |
+
Note: this class interface is deprecated and may be removed in the future.
|
| 218 |
+
Use email.utils.AddressList instead.
|
| 219 |
+
"""
|
| 220 |
+
|
| 221 |
+
def __init__(self, field):
|
| 222 |
+
"""Initialize a new instance.
|
| 223 |
+
|
| 224 |
+
`field' is an unparsed address header field, containing
|
| 225 |
+
one or more addresses.
|
| 226 |
+
"""
|
| 227 |
+
self.specials = '()<>@,:;.\"[]'
|
| 228 |
+
self.pos = 0
|
| 229 |
+
self.LWS = ' \t'
|
| 230 |
+
self.CR = '\r\n'
|
| 231 |
+
self.FWS = self.LWS + self.CR
|
| 232 |
+
self.atomends = self.specials + self.LWS + self.CR
|
| 233 |
+
# Note that RFC 2822 now specifies `.' as obs-phrase, meaning that it
|
| 234 |
+
# is obsolete syntax. RFC 2822 requires that we recognize obsolete
|
| 235 |
+
# syntax, so allow dots in phrases.
|
| 236 |
+
self.phraseends = self.atomends.replace('.', '')
|
| 237 |
+
self.field = field
|
| 238 |
+
self.commentlist = []
|
| 239 |
+
|
| 240 |
+
def gotonext(self):
|
| 241 |
+
"""Skip white space and extract comments."""
|
| 242 |
+
wslist = []
|
| 243 |
+
while self.pos < len(self.field):
|
| 244 |
+
if self.field[self.pos] in self.LWS + '\n\r':
|
| 245 |
+
if self.field[self.pos] not in '\n\r':
|
| 246 |
+
wslist.append(self.field[self.pos])
|
| 247 |
+
self.pos += 1
|
| 248 |
+
elif self.field[self.pos] == '(':
|
| 249 |
+
self.commentlist.append(self.getcomment())
|
| 250 |
+
else:
|
| 251 |
+
break
|
| 252 |
+
return EMPTYSTRING.join(wslist)
|
| 253 |
+
|
| 254 |
+
def getaddrlist(self):
|
| 255 |
+
"""Parse all addresses.
|
| 256 |
+
|
| 257 |
+
Returns a list containing all of the addresses.
|
| 258 |
+
"""
|
| 259 |
+
result = []
|
| 260 |
+
while self.pos < len(self.field):
|
| 261 |
+
ad = self.getaddress()
|
| 262 |
+
if ad:
|
| 263 |
+
result += ad
|
| 264 |
+
else:
|
| 265 |
+
result.append(('', ''))
|
| 266 |
+
return result
|
| 267 |
+
|
| 268 |
+
def getaddress(self):
|
| 269 |
+
"""Parse the next address."""
|
| 270 |
+
self.commentlist = []
|
| 271 |
+
self.gotonext()
|
| 272 |
+
|
| 273 |
+
oldpos = self.pos
|
| 274 |
+
oldcl = self.commentlist
|
| 275 |
+
plist = self.getphraselist()
|
| 276 |
+
|
| 277 |
+
self.gotonext()
|
| 278 |
+
returnlist = []
|
| 279 |
+
|
| 280 |
+
if self.pos >= len(self.field):
|
| 281 |
+
# Bad email address technically, no domain.
|
| 282 |
+
if plist:
|
| 283 |
+
returnlist = [(SPACE.join(self.commentlist), plist[0])]
|
| 284 |
+
|
| 285 |
+
elif self.field[self.pos] in '.@':
|
| 286 |
+
# email address is just an addrspec
|
| 287 |
+
# this isn't very efficient since we start over
|
| 288 |
+
self.pos = oldpos
|
| 289 |
+
self.commentlist = oldcl
|
| 290 |
+
addrspec = self.getaddrspec()
|
| 291 |
+
returnlist = [(SPACE.join(self.commentlist), addrspec)]
|
| 292 |
+
|
| 293 |
+
elif self.field[self.pos] == ':':
|
| 294 |
+
# address is a group
|
| 295 |
+
returnlist = []
|
| 296 |
+
|
| 297 |
+
fieldlen = len(self.field)
|
| 298 |
+
self.pos += 1
|
| 299 |
+
while self.pos < len(self.field):
|
| 300 |
+
self.gotonext()
|
| 301 |
+
if self.pos < fieldlen and self.field[self.pos] == ';':
|
| 302 |
+
self.pos += 1
|
| 303 |
+
break
|
| 304 |
+
returnlist = returnlist + self.getaddress()
|
| 305 |
+
|
| 306 |
+
elif self.field[self.pos] == '<':
|
| 307 |
+
# Address is a phrase then a route addr
|
| 308 |
+
routeaddr = self.getrouteaddr()
|
| 309 |
+
|
| 310 |
+
if self.commentlist:
|
| 311 |
+
returnlist = [(SPACE.join(plist) + ' (' +
|
| 312 |
+
' '.join(self.commentlist) + ')', routeaddr)]
|
| 313 |
+
else:
|
| 314 |
+
returnlist = [(SPACE.join(plist), routeaddr)]
|
| 315 |
+
|
| 316 |
+
else:
|
| 317 |
+
if plist:
|
| 318 |
+
returnlist = [(SPACE.join(self.commentlist), plist[0])]
|
| 319 |
+
elif self.field[self.pos] in self.specials:
|
| 320 |
+
self.pos += 1
|
| 321 |
+
|
| 322 |
+
self.gotonext()
|
| 323 |
+
if self.pos < len(self.field) and self.field[self.pos] == ',':
|
| 324 |
+
self.pos += 1
|
| 325 |
+
return returnlist
|
| 326 |
+
|
| 327 |
+
def getrouteaddr(self):
|
| 328 |
+
"""Parse a route address (Return-path value).
|
| 329 |
+
|
| 330 |
+
This method just skips all the route stuff and returns the addrspec.
|
| 331 |
+
"""
|
| 332 |
+
if self.field[self.pos] != '<':
|
| 333 |
+
return
|
| 334 |
+
|
| 335 |
+
expectroute = False
|
| 336 |
+
self.pos += 1
|
| 337 |
+
self.gotonext()
|
| 338 |
+
adlist = ''
|
| 339 |
+
while self.pos < len(self.field):
|
| 340 |
+
if expectroute:
|
| 341 |
+
self.getdomain()
|
| 342 |
+
expectroute = False
|
| 343 |
+
elif self.field[self.pos] == '>':
|
| 344 |
+
self.pos += 1
|
| 345 |
+
break
|
| 346 |
+
elif self.field[self.pos] == '@':
|
| 347 |
+
self.pos += 1
|
| 348 |
+
expectroute = True
|
| 349 |
+
elif self.field[self.pos] == ':':
|
| 350 |
+
self.pos += 1
|
| 351 |
+
else:
|
| 352 |
+
adlist = self.getaddrspec()
|
| 353 |
+
self.pos += 1
|
| 354 |
+
break
|
| 355 |
+
self.gotonext()
|
| 356 |
+
|
| 357 |
+
return adlist
|
| 358 |
+
|
| 359 |
+
def getaddrspec(self):
|
| 360 |
+
"""Parse an RFC 2822 addr-spec."""
|
| 361 |
+
aslist = []
|
| 362 |
+
|
| 363 |
+
self.gotonext()
|
| 364 |
+
while self.pos < len(self.field):
|
| 365 |
+
preserve_ws = True
|
| 366 |
+
if self.field[self.pos] == '.':
|
| 367 |
+
if aslist and not aslist[-1].strip():
|
| 368 |
+
aslist.pop()
|
| 369 |
+
aslist.append('.')
|
| 370 |
+
self.pos += 1
|
| 371 |
+
preserve_ws = False
|
| 372 |
+
elif self.field[self.pos] == '"':
|
| 373 |
+
aslist.append('"%s"' % quote(self.getquote()))
|
| 374 |
+
elif self.field[self.pos] in self.atomends:
|
| 375 |
+
if aslist and not aslist[-1].strip():
|
| 376 |
+
aslist.pop()
|
| 377 |
+
break
|
| 378 |
+
else:
|
| 379 |
+
aslist.append(self.getatom())
|
| 380 |
+
ws = self.gotonext()
|
| 381 |
+
if preserve_ws and ws:
|
| 382 |
+
aslist.append(ws)
|
| 383 |
+
|
| 384 |
+
if self.pos >= len(self.field) or self.field[self.pos] != '@':
|
| 385 |
+
return EMPTYSTRING.join(aslist)
|
| 386 |
+
|
| 387 |
+
aslist.append('@')
|
| 388 |
+
self.pos += 1
|
| 389 |
+
self.gotonext()
|
| 390 |
+
domain = self.getdomain()
|
| 391 |
+
if not domain:
|
| 392 |
+
# Invalid domain, return an empty address instead of returning a
|
| 393 |
+
# local part to denote failed parsing.
|
| 394 |
+
return EMPTYSTRING
|
| 395 |
+
return EMPTYSTRING.join(aslist) + domain
|
| 396 |
+
|
| 397 |
+
def getdomain(self):
|
| 398 |
+
"""Get the complete domain name from an address."""
|
| 399 |
+
sdlist = []
|
| 400 |
+
while self.pos < len(self.field):
|
| 401 |
+
if self.field[self.pos] in self.LWS:
|
| 402 |
+
self.pos += 1
|
| 403 |
+
elif self.field[self.pos] == '(':
|
| 404 |
+
self.commentlist.append(self.getcomment())
|
| 405 |
+
elif self.field[self.pos] == '[':
|
| 406 |
+
sdlist.append(self.getdomainliteral())
|
| 407 |
+
elif self.field[self.pos] == '.':
|
| 408 |
+
self.pos += 1
|
| 409 |
+
sdlist.append('.')
|
| 410 |
+
elif self.field[self.pos] == '@':
|
| 411 |
+
# bpo-34155: Don't parse domains with two `@` like
|
| 412 |
+
# `[email protected]@important.com`.
|
| 413 |
+
return EMPTYSTRING
|
| 414 |
+
elif self.field[self.pos] in self.atomends:
|
| 415 |
+
break
|
| 416 |
+
else:
|
| 417 |
+
sdlist.append(self.getatom())
|
| 418 |
+
return EMPTYSTRING.join(sdlist)
|
| 419 |
+
|
| 420 |
+
def getdelimited(self, beginchar, endchars, allowcomments=True):
|
| 421 |
+
"""Parse a header fragment delimited by special characters.
|
| 422 |
+
|
| 423 |
+
`beginchar' is the start character for the fragment.
|
| 424 |
+
If self is not looking at an instance of `beginchar' then
|
| 425 |
+
getdelimited returns the empty string.
|
| 426 |
+
|
| 427 |
+
`endchars' is a sequence of allowable end-delimiting characters.
|
| 428 |
+
Parsing stops when one of these is encountered.
|
| 429 |
+
|
| 430 |
+
If `allowcomments' is non-zero, embedded RFC 2822 comments are allowed
|
| 431 |
+
within the parsed fragment.
|
| 432 |
+
"""
|
| 433 |
+
if self.field[self.pos] != beginchar:
|
| 434 |
+
return ''
|
| 435 |
+
|
| 436 |
+
slist = ['']
|
| 437 |
+
quote = False
|
| 438 |
+
self.pos += 1
|
| 439 |
+
while self.pos < len(self.field):
|
| 440 |
+
if quote:
|
| 441 |
+
slist.append(self.field[self.pos])
|
| 442 |
+
quote = False
|
| 443 |
+
elif self.field[self.pos] in endchars:
|
| 444 |
+
self.pos += 1
|
| 445 |
+
break
|
| 446 |
+
elif allowcomments and self.field[self.pos] == '(':
|
| 447 |
+
slist.append(self.getcomment())
|
| 448 |
+
continue # have already advanced pos from getcomment
|
| 449 |
+
elif self.field[self.pos] == '\\':
|
| 450 |
+
quote = True
|
| 451 |
+
else:
|
| 452 |
+
slist.append(self.field[self.pos])
|
| 453 |
+
self.pos += 1
|
| 454 |
+
|
| 455 |
+
return EMPTYSTRING.join(slist)
|
| 456 |
+
|
| 457 |
+
def getquote(self):
|
| 458 |
+
"""Get a quote-delimited fragment from self's field."""
|
| 459 |
+
return self.getdelimited('"', '"\r', False)
|
| 460 |
+
|
| 461 |
+
def getcomment(self):
|
| 462 |
+
"""Get a parenthesis-delimited fragment from self's field."""
|
| 463 |
+
return self.getdelimited('(', ')\r', True)
|
| 464 |
+
|
| 465 |
+
def getdomainliteral(self):
|
| 466 |
+
"""Parse an RFC 2822 domain-literal."""
|
| 467 |
+
return '[%s]' % self.getdelimited('[', ']\r', False)
|
| 468 |
+
|
| 469 |
+
def getatom(self, atomends=None):
|
| 470 |
+
"""Parse an RFC 2822 atom.
|
| 471 |
+
|
| 472 |
+
Optional atomends specifies a different set of end token delimiters
|
| 473 |
+
(the default is to use self.atomends). This is used e.g. in
|
| 474 |
+
getphraselist() since phrase endings must not include the `.' (which
|
| 475 |
+
is legal in phrases)."""
|
| 476 |
+
atomlist = ['']
|
| 477 |
+
if atomends is None:
|
| 478 |
+
atomends = self.atomends
|
| 479 |
+
|
| 480 |
+
while self.pos < len(self.field):
|
| 481 |
+
if self.field[self.pos] in atomends:
|
| 482 |
+
break
|
| 483 |
+
else:
|
| 484 |
+
atomlist.append(self.field[self.pos])
|
| 485 |
+
self.pos += 1
|
| 486 |
+
|
| 487 |
+
return EMPTYSTRING.join(atomlist)
|
| 488 |
+
|
| 489 |
+
def getphraselist(self):
|
| 490 |
+
"""Parse a sequence of RFC 2822 phrases.
|
| 491 |
+
|
| 492 |
+
A phrase is a sequence of words, which are in turn either RFC 2822
|
| 493 |
+
atoms or quoted-strings. Phrases are canonicalized by squeezing all
|
| 494 |
+
runs of continuous whitespace into one space.
|
| 495 |
+
"""
|
| 496 |
+
plist = []
|
| 497 |
+
|
| 498 |
+
while self.pos < len(self.field):
|
| 499 |
+
if self.field[self.pos] in self.FWS:
|
| 500 |
+
self.pos += 1
|
| 501 |
+
elif self.field[self.pos] == '"':
|
| 502 |
+
plist.append(self.getquote())
|
| 503 |
+
elif self.field[self.pos] == '(':
|
| 504 |
+
self.commentlist.append(self.getcomment())
|
| 505 |
+
elif self.field[self.pos] in self.phraseends:
|
| 506 |
+
break
|
| 507 |
+
else:
|
| 508 |
+
plist.append(self.getatom(self.phraseends))
|
| 509 |
+
|
| 510 |
+
return plist
|
| 511 |
+
|
| 512 |
+
class AddressList(AddrlistClass):
|
| 513 |
+
"""An AddressList encapsulates a list of parsed RFC 2822 addresses."""
|
| 514 |
+
def __init__(self, field):
|
| 515 |
+
AddrlistClass.__init__(self, field)
|
| 516 |
+
if field:
|
| 517 |
+
self.addresslist = self.getaddrlist()
|
| 518 |
+
else:
|
| 519 |
+
self.addresslist = []
|
| 520 |
+
|
| 521 |
+
def __len__(self):
|
| 522 |
+
return len(self.addresslist)
|
| 523 |
+
|
| 524 |
+
def __add__(self, other):
|
| 525 |
+
# Set union
|
| 526 |
+
newaddr = AddressList(None)
|
| 527 |
+
newaddr.addresslist = self.addresslist[:]
|
| 528 |
+
for x in other.addresslist:
|
| 529 |
+
if not x in self.addresslist:
|
| 530 |
+
newaddr.addresslist.append(x)
|
| 531 |
+
return newaddr
|
| 532 |
+
|
| 533 |
+
def __iadd__(self, other):
|
| 534 |
+
# Set union, in-place
|
| 535 |
+
for x in other.addresslist:
|
| 536 |
+
if not x in self.addresslist:
|
| 537 |
+
self.addresslist.append(x)
|
| 538 |
+
return self
|
| 539 |
+
|
| 540 |
+
def __sub__(self, other):
|
| 541 |
+
# Set difference
|
| 542 |
+
newaddr = AddressList(None)
|
| 543 |
+
for x in self.addresslist:
|
| 544 |
+
if not x in other.addresslist:
|
| 545 |
+
newaddr.addresslist.append(x)
|
| 546 |
+
return newaddr
|
| 547 |
+
|
| 548 |
+
def __isub__(self, other):
|
| 549 |
+
# Set difference, in-place
|
| 550 |
+
for x in other.addresslist:
|
| 551 |
+
if x in self.addresslist:
|
| 552 |
+
self.addresslist.remove(x)
|
| 553 |
+
return self
|
| 554 |
+
|
| 555 |
+
def __getitem__(self, index):
|
| 556 |
+
# Make indexing, slices, and 'in' work
|
| 557 |
+
return self.addresslist[index]
|
janus/lib/python3.10/email/_policybase.py
ADDED
|
@@ -0,0 +1,382 @@
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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()
|
janus/lib/python3.10/email/architecture.rst
ADDED
|
@@ -0,0 +1,216 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
:mod:`email` Package Architecture
|
| 2 |
+
=================================
|
| 3 |
+
|
| 4 |
+
Overview
|
| 5 |
+
--------
|
| 6 |
+
|
| 7 |
+
The email package consists of three major components:
|
| 8 |
+
|
| 9 |
+
Model
|
| 10 |
+
An object structure that represents an email message, and provides an
|
| 11 |
+
API for creating, querying, and modifying a message.
|
| 12 |
+
|
| 13 |
+
Parser
|
| 14 |
+
Takes a sequence of characters or bytes and produces a model of the
|
| 15 |
+
email message represented by those characters or bytes.
|
| 16 |
+
|
| 17 |
+
Generator
|
| 18 |
+
Takes a model and turns it into a sequence of characters or bytes. The
|
| 19 |
+
sequence can either be intended for human consumption (a printable
|
| 20 |
+
unicode string) or bytes suitable for transmission over the wire. In
|
| 21 |
+
the latter case all data is properly encoded using the content transfer
|
| 22 |
+
encodings specified by the relevant RFCs.
|
| 23 |
+
|
| 24 |
+
Conceptually the package is organized around the model. The model provides both
|
| 25 |
+
"external" APIs intended for use by application programs using the library,
|
| 26 |
+
and "internal" APIs intended for use by the Parser and Generator components.
|
| 27 |
+
This division is intentionally a bit fuzzy; the API described by this
|
| 28 |
+
documentation is all a public, stable API. This allows for an application
|
| 29 |
+
with special needs to implement its own parser and/or generator.
|
| 30 |
+
|
| 31 |
+
In addition to the three major functional components, there is a third key
|
| 32 |
+
component to the architecture:
|
| 33 |
+
|
| 34 |
+
Policy
|
| 35 |
+
An object that specifies various behavioral settings and carries
|
| 36 |
+
implementations of various behavior-controlling methods.
|
| 37 |
+
|
| 38 |
+
The Policy framework provides a simple and convenient way to control the
|
| 39 |
+
behavior of the library, making it possible for the library to be used in a
|
| 40 |
+
very flexible fashion while leveraging the common code required to parse,
|
| 41 |
+
represent, and generate message-like objects. For example, in addition to the
|
| 42 |
+
default :rfc:`5322` email message policy, we also have a policy that manages
|
| 43 |
+
HTTP headers in a fashion compliant with :rfc:`2616`. Individual policy
|
| 44 |
+
controls, such as the maximum line length produced by the generator, can also
|
| 45 |
+
be controlled individually to meet specialized application requirements.
|
| 46 |
+
|
| 47 |
+
|
| 48 |
+
The Model
|
| 49 |
+
---------
|
| 50 |
+
|
| 51 |
+
The message model is implemented by the :class:`~email.message.Message` class.
|
| 52 |
+
The model divides a message into the two fundamental parts discussed by the
|
| 53 |
+
RFC: the header section and the body. The `Message` object acts as a
|
| 54 |
+
pseudo-dictionary of named headers. Its dictionary interface provides
|
| 55 |
+
convenient access to individual headers by name. However, all headers are kept
|
| 56 |
+
internally in an ordered list, so that the information about the order of the
|
| 57 |
+
headers in the original message is preserved.
|
| 58 |
+
|
| 59 |
+
The `Message` object also has a `payload` that holds the body. A `payload` can
|
| 60 |
+
be one of two things: data, or a list of `Message` objects. The latter is used
|
| 61 |
+
to represent a multipart MIME message. Lists can be nested arbitrarily deeply
|
| 62 |
+
in order to represent the message, with all terminal leaves having non-list
|
| 63 |
+
data payloads.
|
| 64 |
+
|
| 65 |
+
|
| 66 |
+
Message Lifecycle
|
| 67 |
+
-----------------
|
| 68 |
+
|
| 69 |
+
The general lifecycle of a message is:
|
| 70 |
+
|
| 71 |
+
Creation
|
| 72 |
+
A `Message` object can be created by a Parser, or it can be
|
| 73 |
+
instantiated as an empty message by an application.
|
| 74 |
+
|
| 75 |
+
Manipulation
|
| 76 |
+
The application may examine one or more headers, and/or the
|
| 77 |
+
payload, and it may modify one or more headers and/or
|
| 78 |
+
the payload. This may be done on the top level `Message`
|
| 79 |
+
object, or on any sub-object.
|
| 80 |
+
|
| 81 |
+
Finalization
|
| 82 |
+
The Model is converted into a unicode or binary stream,
|
| 83 |
+
or the model is discarded.
|
| 84 |
+
|
| 85 |
+
|
| 86 |
+
|
| 87 |
+
Header Policy Control During Lifecycle
|
| 88 |
+
--------------------------------------
|
| 89 |
+
|
| 90 |
+
One of the major controls exerted by the Policy is the management of headers
|
| 91 |
+
during the `Message` lifecycle. Most applications don't need to be aware of
|
| 92 |
+
this.
|
| 93 |
+
|
| 94 |
+
A header enters the model in one of two ways: via a Parser, or by being set to
|
| 95 |
+
a specific value by an application program after the Model already exists.
|
| 96 |
+
Similarly, a header exits the model in one of two ways: by being serialized by
|
| 97 |
+
a Generator, or by being retrieved from a Model by an application program. The
|
| 98 |
+
Policy object provides hooks for all four of these pathways.
|
| 99 |
+
|
| 100 |
+
The model storage for headers is a list of (name, value) tuples.
|
| 101 |
+
|
| 102 |
+
The Parser identifies headers during parsing, and passes them to the
|
| 103 |
+
:meth:`~email.policy.Policy.header_source_parse` method of the Policy. The
|
| 104 |
+
result of that method is the (name, value) tuple to be stored in the model.
|
| 105 |
+
|
| 106 |
+
When an application program supplies a header value (for example, through the
|
| 107 |
+
`Message` object `__setitem__` interface), the name and the value are passed to
|
| 108 |
+
the :meth:`~email.policy.Policy.header_store_parse` method of the Policy, which
|
| 109 |
+
returns the (name, value) tuple to be stored in the model.
|
| 110 |
+
|
| 111 |
+
When an application program retrieves a header (through any of the dict or list
|
| 112 |
+
interfaces of `Message`), the name and value are passed to the
|
| 113 |
+
:meth:`~email.policy.Policy.header_fetch_parse` method of the Policy to
|
| 114 |
+
obtain the value returned to the application.
|
| 115 |
+
|
| 116 |
+
When a Generator requests a header during serialization, the name and value are
|
| 117 |
+
passed to the :meth:`~email.policy.Policy.fold` method of the Policy, which
|
| 118 |
+
returns a string containing line breaks in the appropriate places. The
|
| 119 |
+
:meth:`~email.policy.Policy.cte_type` Policy control determines whether or
|
| 120 |
+
not Content Transfer Encoding is performed on the data in the header. There is
|
| 121 |
+
also a :meth:`~email.policy.Policy.binary_fold` method for use by generators
|
| 122 |
+
that produce binary output, which returns the folded header as binary data,
|
| 123 |
+
possibly folded at different places than the corresponding string would be.
|
| 124 |
+
|
| 125 |
+
|
| 126 |
+
Handling Binary Data
|
| 127 |
+
--------------------
|
| 128 |
+
|
| 129 |
+
In an ideal world all message data would conform to the RFCs, meaning that the
|
| 130 |
+
parser could decode the message into the idealized unicode message that the
|
| 131 |
+
sender originally wrote. In the real world, the email package must also be
|
| 132 |
+
able to deal with badly formatted messages, including messages containing
|
| 133 |
+
non-ASCII characters that either have no indicated character set or are not
|
| 134 |
+
valid characters in the indicated character set.
|
| 135 |
+
|
| 136 |
+
Since email messages are *primarily* text data, and operations on message data
|
| 137 |
+
are primarily text operations (except for binary payloads of course), the model
|
| 138 |
+
stores all text data as unicode strings. Un-decodable binary inside text
|
| 139 |
+
data is handled by using the `surrogateescape` error handler of the ASCII
|
| 140 |
+
codec. As with the binary filenames the error handler was introduced to
|
| 141 |
+
handle, this allows the email package to "carry" the binary data received
|
| 142 |
+
during parsing along until the output stage, at which time it is regenerated
|
| 143 |
+
in its original form.
|
| 144 |
+
|
| 145 |
+
This carried binary data is almost entirely an implementation detail. The one
|
| 146 |
+
place where it is visible in the API is in the "internal" API. A Parser must
|
| 147 |
+
do the `surrogateescape` encoding of binary input data, and pass that data to
|
| 148 |
+
the appropriate Policy method. The "internal" interface used by the Generator
|
| 149 |
+
to access header values preserves the `surrogateescaped` bytes. All other
|
| 150 |
+
interfaces convert the binary data either back into bytes or into a safe form
|
| 151 |
+
(losing information in some cases).
|
| 152 |
+
|
| 153 |
+
|
| 154 |
+
Backward Compatibility
|
| 155 |
+
----------------------
|
| 156 |
+
|
| 157 |
+
The :class:`~email.policy.Policy.Compat32` Policy provides backward
|
| 158 |
+
compatibility with version 5.1 of the email package. It does this via the
|
| 159 |
+
following implementation of the four+1 Policy methods described above:
|
| 160 |
+
|
| 161 |
+
header_source_parse
|
| 162 |
+
Splits the first line on the colon to obtain the name, discards any spaces
|
| 163 |
+
after the colon, and joins the remainder of the line with all of the
|
| 164 |
+
remaining lines, preserving the linesep characters to obtain the value.
|
| 165 |
+
Trailing carriage return and/or linefeed characters are stripped from the
|
| 166 |
+
resulting value string.
|
| 167 |
+
|
| 168 |
+
header_store_parse
|
| 169 |
+
Returns the name and value exactly as received from the application.
|
| 170 |
+
|
| 171 |
+
header_fetch_parse
|
| 172 |
+
If the value contains any `surrogateescaped` binary data, return the value
|
| 173 |
+
as a :class:`~email.header.Header` object, using the character set
|
| 174 |
+
`unknown-8bit`. Otherwise just returns the value.
|
| 175 |
+
|
| 176 |
+
fold
|
| 177 |
+
Uses :class:`~email.header.Header`'s folding to fold headers in the
|
| 178 |
+
same way the email5.1 generator did.
|
| 179 |
+
|
| 180 |
+
binary_fold
|
| 181 |
+
Same as fold, but encodes to 'ascii'.
|
| 182 |
+
|
| 183 |
+
|
| 184 |
+
New Algorithm
|
| 185 |
+
-------------
|
| 186 |
+
|
| 187 |
+
header_source_parse
|
| 188 |
+
Same as legacy behavior.
|
| 189 |
+
|
| 190 |
+
header_store_parse
|
| 191 |
+
Same as legacy behavior.
|
| 192 |
+
|
| 193 |
+
header_fetch_parse
|
| 194 |
+
If the value is already a header object, returns it. Otherwise, parses the
|
| 195 |
+
value using the new parser, and returns the resulting object as the value.
|
| 196 |
+
`surrogateescaped` bytes get turned into unicode unknown character code
|
| 197 |
+
points.
|
| 198 |
+
|
| 199 |
+
fold
|
| 200 |
+
Uses the new header folding algorithm, respecting the policy settings.
|
| 201 |
+
surrogateescaped bytes are encoded using the ``unknown-8bit`` charset for
|
| 202 |
+
``cte_type=7bit`` or ``8bit``. Returns a string.
|
| 203 |
+
|
| 204 |
+
At some point there will also be a ``cte_type=unicode``, and for that
|
| 205 |
+
policy fold will serialize the idealized unicode message with RFC-like
|
| 206 |
+
folding, converting any surrogateescaped bytes into the unicode
|
| 207 |
+
unknown character glyph.
|
| 208 |
+
|
| 209 |
+
binary_fold
|
| 210 |
+
Uses the new header folding algorithm, respecting the policy settings.
|
| 211 |
+
surrogateescaped bytes are encoded using the `unknown-8bit` charset for
|
| 212 |
+
``cte_type=7bit``, and get turned back into bytes for ``cte_type=8bit``.
|
| 213 |
+
Returns bytes.
|
| 214 |
+
|
| 215 |
+
At some point there will also be a ``cte_type=unicode``, and for that
|
| 216 |
+
policy binary_fold will serialize the message according to :rfc:``5335``.
|