MCPcopy Create free account
hub / github.com/RT-Thread/env-windows / Generator

Class Generator

tools/python-3.11.9-amd64/Lib/email/generator.py:25–392  ·  view source on GitHub ↗

Generates output from a Message object tree. This basic generator writes the message to the given file object as plain text.

Source from the content-addressed store, hash-verified

23
24
25class Generator:
26 """Generates output from a Message object tree.
27
28 This basic generator writes the message to the given file object as plain
29 text.
30 """
31 #
32 # Public interface
33 #
34
35 def __init__(self, outfp, mangle_from_=None, maxheaderlen=None, *,
36 policy=None):
37 """Create the generator for message flattening.
38
39 outfp is the output file-like object for writing the message to. It
40 must have a write() method.
41
42 Optional mangle_from_ is a flag that, when True (the default if policy
43 is not set), escapes From_ lines in the body of the message by putting
44 a `>' in front of them.
45
46 Optional maxheaderlen specifies the longest length for a non-continued
47 header. When a header line is longer (in characters, with tabs
48 expanded to 8 spaces) than maxheaderlen, the header will split as
49 defined in the Header class. Set maxheaderlen to zero to disable
50 header wrapping. The default is 78, as recommended (but not required)
51 by RFC 2822.
52
53 The policy keyword specifies a policy object that controls a number of
54 aspects of the generator's operation. If no policy is specified,
55 the policy associated with the Message object passed to the
56 flatten method is used.
57
58 """
59
60 if mangle_from_ is None:
61 mangle_from_ = True if policy is None else policy.mangle_from_
62 self._fp = outfp
63 self._mangle_from_ = mangle_from_
64 self.maxheaderlen = maxheaderlen
65 self.policy = policy
66
67 def write(self, s):
68 # Just delegate to the file object
69 self._fp.write(s)
70
71 def flatten(self, msg, unixfrom=False, linesep=None):
72 r"""Print the message object tree rooted at msg to the output file
73 specified when the Generator instance was created.
74
75 unixfrom is a flag that forces the printing of a Unix From_ delimiter
76 before the first object in the message tree. If the original message
77 has no From_ delimiter, a `standard' one is crafted. By default, this
78 is False to inhibit the printing of any From_ delimiter.
79
80 Note that for subobjects, no From_ line is printed.
81
82 linesep specifies the characters used to indicate a new line in

Callers 1

as_stringMethod · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected