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

Method as_string

Lib/email/message.py:173–195  ·  view source on GitHub ↗

Return the entire formatted message as a string. Optional 'unixfrom', when true, means include the Unix From_ envelope header. For backward compatibility reasons, if maxheaderlen is not specified it defaults to 0, so you must override it explicitly if you want a dif

(self, unixfrom=False, maxheaderlen=0, policy=None)

Source from the content-addressed store, hash-verified

171 return self.as_string()
172
173 def as_string(self, unixfrom=False, maxheaderlen=0, policy=None):
174 """Return the entire formatted message as a string.
175
176 Optional 'unixfrom', when true, means include the Unix From_ envelope
177 header. For backward compatibility reasons, if maxheaderlen is
178 not specified it defaults to 0, so you must override it explicitly
179 if you want a different maxheaderlen. 'policy' is passed to the
180 Generator instance used to serialize the message; if it is not
181 specified the policy associated with the message instance is used.
182
183 If the message object contains binary data that is not encoded
184 according to RFC standards, the non-compliant data will be replaced by
185 unicode "unknown character" code points.
186 """
187 from email.generator import Generator
188 policy = self.policy if policy is None else policy
189 fp = StringIO()
190 g = Generator(fp,
191 mangle_from_=False,
192 maxheaderlen=maxheaderlen,
193 policy=policy)
194 g.flatten(self, unixfrom=unixfrom)
195 return fp.getvalue()
196
197 def __bytes__(self):
198 """Return the entire formatted message as a bytes object.

Callers 15

__str__Method · 0.95
test_long_8bit_headerMethod · 0.95
test_long_to_headerMethod · 0.95
test_no_nl_preambleMethod · 0.95
test_set_paramMethod · 0.95
get_stringMethod · 0.45
get_stringMethod · 0.45

Calls 4

flattenMethod · 0.95
getvalueMethod · 0.95
StringIOClass · 0.90
GeneratorClass · 0.90