U e[ @sddlmZddlZddlZddlZddlZddlmZddlm Z m Z e ddZ ej ejejee fe fZejeejee ffZdd d d Zd d dddZdd dddddZdS)) annotationsN)BytesIO)_TYPE_FIELD_VALUE_TUPLE RequestFieldzutf-8str)returncCsttdS)zN Our embarrassingly-simple replacement for mimetools.choose_boundary. )binasciihexlifyosurandomdecoderr>/opt/hc_python/lib/python3.8/site-packages/urllib3/filepost.pychoose_boundarysr _TYPE_FIELDSztyping.Iterable[RequestField])fieldsr ccsFt|tjr|}n|}|D]"}t|tr4|Vqtj|VqdS)z Iterate over fields. Supports list of (k, v) tuples and dicts, and lists of :class:`~urllib3.fields.RequestField`. N) isinstancetypingMappingitemsr from_tuples)riterablefieldrrriter_field_objectss   rz str | Noneztuple[bytes, str])rboundaryr cCst}|dkrt}t|D]t}|d|ddt|||j}t|t rbt |}t|t r|t||n |||dq|d|ddd|}| |fS)a Encode a dictionary of ``fields`` using the multipart/form-data MIME format. :param fields: Dictionary of fields or list of (key, :class:`~urllib3.fields.RequestField`). Values are processed by :func:`urllib3.fields.RequestField.from_tuples`. :param boundary: If not specified, then a random boundary will be generated using :func:`urllib3.filepost.choose_boundary`. Nz--z zlatin-1s z-- zmultipart/form-data; boundary=) rrrwriteencodewriterrender_headersdatarintrgetvalue)rrbodyrr" content_typerrrencode_multipart_formdata3s       r')N) __future__rr codecsr riorrrrlookupr SequenceUnionTuplerZ_TYPE_FIELDS_SEQUENCErrrrr'rrrrs&