MCPcopy Index your code
hub / github.com/matplotlib/matplotlib / encode_multipart_formdata

Function encode_multipart_formdata

tools/gh_api.py:208–261  ·  view source on GitHub ↗

Encode a dictionary of ``fields`` using the multipart/form-data mime format. :param fields: Dictionary of fields or list of (key, value) field tuples. The key is treated as the field name, and the value as the body of the form-data bytes. If the value is a tuple of

(fields, boundary=None)

Source from the content-addressed store, hash-verified

206 yield from fields.items()
207
208def encode_multipart_formdata(fields, boundary=None):
209 """
210 Encode a dictionary of ``fields`` using the multipart/form-data mime format.
211
212 :param fields:
213 Dictionary of fields or list of (key, value) field tuples. The key is
214 treated as the field name, and the value as the body of the form-data
215 bytes. If the value is a tuple of two elements, then the first element
216 is treated as the filename of the form-data section.
217
218 Field names and filenames must be str.
219
220 :param boundary:
221 If not specified, then a random boundary will be generated using
222 :func:`mimetools.choose_boundary`.
223 """
224 # copy requests imports in here:
225 from io import BytesIO
226 from requests.packages.urllib3.filepost import (
227 choose_boundary, writer, b, get_content_type
228 )
229 body = BytesIO()
230 if boundary is None:
231 boundary = choose_boundary()
232
233 for fieldname, value in iter_fields(fields):
234 body.write(b('--%s\r\n' % (boundary)))
235
236 if isinstance(value, tuple):
237 filename, data = value
238 writer(body).write('Content-Disposition: form-data; name="%s"; '
239 'filename="%s"\r\n' % (fieldname, filename))
240 body.write(b('Content-Type: %s\r\n\r\n' %
241 (get_content_type(filename))))
242 else:
243 data = value
244 writer(body).write('Content-Disposition: form-data; name="%s"\r\n'
245 % (fieldname))
246 body.write(b'Content-Type: text/plain\r\n\r\n')
247
248 if isinstance(data, int):
249 data = str(data) # Backwards compatibility
250 if isinstance(data, str):
251 writer(body).write(data)
252 else:
253 body.write(data)
254
255 body.write(b'\r\n')
256
257 body.write(b('--%s--\r\n' % (boundary)))
258
259 content_type = b('multipart/form-data; boundary=%s' % boundary)
260
261 return body.getvalue(), content_type
262
263
264def post_download(project, filename, name=None, description=""):

Callers 1

post_downloadFunction · 0.85

Calls 2

iter_fieldsFunction · 0.85
writeMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…