MCPcopy Index your code
hub / github.com/RustPython/RustPython / flatten

Method flatten

Lib/email/generator.py:73–120  ·  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

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