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

Method _write

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

Source from the content-addressed store, hash-verified

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

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

Tested by

no test coverage detected