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

Method _write

Lib/email/generator.py:167–204  ·  view source on GitHub ↗
(self, msg)

Source from the content-addressed store, hash-verified

165 # self.write(self._NL)
166
167 def _write(self, msg):
168 # We can't write the headers yet because of the following scenario:
169 # say a multipart message includes the boundary string somewhere in
170 # its body. We'd have to calculate the new boundary /before/ we write
171 # the headers so that we can write the correct Content-Type:
172 # parameter.
173 #
174 # The way we do this, so as to make the _handle_*() methods simpler,
175 # is to cache any subpart writes into a buffer. Then we write the
176 # headers and the buffer contents. That way, subpart handlers can
177 # Do The Right Thing, and can still modify the Content-Type: header if
178 # necessary.
179 oldfp = self._fp
180 try:
181 self._munge_cte = None
182 self._fp = sfp = self._new_buffer()
183 self._dispatch(msg)
184 finally:
185 self._fp = oldfp
186 munge_cte = self._munge_cte
187 del self._munge_cte
188 # If we munged the cte, copy the message again and re-fix the CTE.
189 if munge_cte:
190 msg = deepcopy(msg)
191 # Preserve the header order if the CTE header already exists.
192 if msg.get('content-transfer-encoding') is None:
193 msg['Content-Transfer-Encoding'] = munge_cte[0]
194 else:
195 msg.replace_header('content-transfer-encoding', munge_cte[0])
196 msg.replace_header('content-type', munge_cte[1])
197 # Write the headers. First we see if the message object wants to
198 # handle that itself. If not, we'll do it generically.
199 meth = getattr(msg, '_write_headers', None)
200 if meth is None:
201 self._write_headers(msg)
202 else:
203 meth(self)
204 self._fp.write(sfp.getvalue())
205
206 def _dispatch(self, msg):
207 # Get the Content-Type: for the message, then try to dispatch to

Callers 14

flattenMethod · 0.95
_flushMethod · 0.45
endMethod · 0.45
commentMethod · 0.45
piMethod · 0.45
startDocumentMethod · 0.45
startElementMethod · 0.45
endElementMethod · 0.45
startElementNSMethod · 0.45
endElementNSMethod · 0.45
charactersMethod · 0.45

Calls 9

_new_bufferMethod · 0.95
_dispatchMethod · 0.95
_write_headersMethod · 0.95
deepcopyFunction · 0.90
methFunction · 0.85
replace_headerMethod · 0.80
getMethod · 0.45
writeMethod · 0.45
getvalueMethod · 0.45

Tested by

no test coverage detected