3 nf·\„ ã@sˆddlmZddlZddlZddlZddlmZddlmZddl m Z ddl m Z ej dƒd Zd d „Zd d „Zdd„Zddd„ZdS)é)Úabsolute_importN)ÚBytesIOé)Úsix)Úb)Ú RequestFieldzutf-8écCs$tjtjdƒƒ}tjr |jdƒ}|S)zN Our embarrassingly-simple replacement for mimetools.choose_boundary. éÚascii)ÚbinasciiZhexlifyÚosÚurandomrZPY3Údecode)Úboundary©rú/usr/lib/python3.6/filepost.pyÚchoose_boundarys rccsNt|tƒrtj|ƒ}nt|ƒ}x*|D]"}t|tƒr:|Vq$tj|ŽVq$WdS)z† Iterate over fields. Supports list of (k, v) tuples and dicts, and lists of :class:`~urllib3.fields.RequestField`. N)Ú isinstanceÚdictrÚ iteritemsÚiterrZ from_tuples)ÚfieldsÚiÚfieldrrrÚiter_field_objectss    rcCs,t|tƒrdd„tj|ƒDƒSdd„|DƒS)a- .. deprecated:: 1.6 Iterate over fields. The addition of :class:`~urllib3.fields.RequestField` makes this function obsolete. Instead, use :func:`iter_field_objects`, which returns :class:`~urllib3.fields.RequestField` objects. Supports list of (k, v) tuples and dicts. css|]\}}||fVqdS)Nr)Ú.0ÚkÚvrrrú :sziter_fields..css|]\}}||fVqdS)Nr)rrrrrrr<s)rrrr)rrrrÚ iter_fields-s rcCs¼tƒ}|dkrtƒ}x|t|ƒD]p}|jtd|ƒƒt|ƒj|jƒƒ|j}t|t ƒr^t |ƒ}t|t j ƒrzt|ƒj|ƒn |j|ƒ|jdƒqW|jtd|ƒƒt d|ƒ}|j ƒ|fS)aQ 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`). :param boundary: If not specified, then a random boundary will be generated using :func:`urllib3.filepost.choose_boundary`. Nz--%s s z--%s-- z multipart/form-data; boundary=%s)rrrÚwriterÚwriterZrender_headersÚdatarÚintÚstrrZ text_typeÚgetvalue)rrZbodyrr"Z content_typerrrÚencode_multipart_formdata?s     r&)N)Z __future__rr Úcodecsr ÚiorZpackagesrZ packages.sixrrrÚlookupr!rrrr&rrrrÚs