MCPcopy Index your code
hub / github.com/python/cpython / flatten

Method flatten

Lib/email/generator.py:74–121  ·  view source on GitHub ↗

r"""Print the message object tree rooted at msg to the output file specified when the Generator instance was created. unixfrom is a flag that forces the printing of a Unix From_ delimiter before the first object in the message tree. If the original message has no Fr

(self, msg, unixfrom=False, linesep=None)

Source from the content-addressed store, hash-verified

72 self._fp.write(s)
73
74 def flatten(self, msg, unixfrom=False, linesep=None):
75 r"""Print the message object tree rooted at msg to the output file
76 specified when the Generator instance was created.
77
78 unixfrom is a flag that forces the printing of a Unix From_ delimiter
79 before the first object in the message tree. If the original message
80 has no From_ delimiter, a 'standard' one is crafted. By default, this
81 is False to inhibit the printing of any From_ delimiter.
82
83 Note that for subobjects, no From_ line is printed.
84
85 linesep specifies the characters used to indicate a new line in
86 the output. The default value is determined by the policy specified
87 when the Generator instance was created or, if none was specified,
88 from the policy associated with the msg.
89
90 """
91 # We use the _XXX constants for operating on data that comes directly
92 # from the msg, and _encoded_XXX constants for operating on data that
93 # has already been converted (to bytes in the BytesGenerator) and
94 # inserted into a temporary buffer.
95 policy = msg.policy if self.policy is None else self.policy
96 if linesep is not None:
97 policy = policy.clone(linesep=linesep)
98 if self.maxheaderlen is not None:
99 policy = policy.clone(max_line_length=self.maxheaderlen)
100 self._NL = policy.linesep
101 self._encoded_NL = self._encode(self._NL)
102 self._EMPTY = ''
103 self._encoded_EMPTY = self._encode(self._EMPTY)
104 # Because we use clone (below) when we recursively process message
105 # subparts, and because clone uses the computed policy (not None),
106 # submessages will automatically get set to the computed policy when
107 # they are processed by this code.
108 old_gen_policy = self.policy
109 old_msg_policy = msg.policy
110 try:
111 self.policy = policy
112 msg.policy = policy
113 if unixfrom:
114 ufrom = msg.get_unixfrom()
115 if not ufrom:
116 ufrom = 'From nobody ' + time.ctime(time.time())
117 self.write(ufrom + self._NL)
118 self._write(msg)
119 finally:
120 self.policy = old_gen_policy
121 msg.policy = old_msg_policy
122
123 def clone(self, fp):
124 """Clone this generator with the exact same options."""

Calls 7

_encodeMethod · 0.95
writeMethod · 0.95
_writeMethod · 0.95
get_unixfromMethod · 0.80
cloneMethod · 0.45
ctimeMethod · 0.45
timeMethod · 0.45