3

Z'ícˆ	ã@sˆddlmZddlZddlZddlZddlmZddlmZddl	m
Z
ddlmZej
dƒd	Zd
d„Zdd
„Zdd„Zddd„ZdS)é)Úabsolute_importN)ÚBytesIOé)ÚRequestField)Úsix)Úbzutf-8écCs$tjtjdƒƒ}tjs |jdƒ}|S)zN
    Our embarrassingly-simple replacement for mimetools.choose_boundary.
    éÚascii)ÚbinasciiÚhexlifyÚosÚurandomrÚPY2Údecode)Úboundary©rú3/tmp/pip-build-gk9425m9/urllib3/urllib3/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ÚiterrÚ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ú	<genexpr>:sziter_fields.<locals>.<genexpr>css|]\}}||fVqdS)Nr)rrr rrrr!<s)rrrr)rrrrÚiter_fields-s
r"cCs¼tƒ}|dkrtƒ}x|t|ƒD]p}|jtd|ƒƒt|ƒj|jƒƒ|j}t|t	ƒr^t
|ƒ}t|tjƒ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ÚwriterÚrender_headersÚdatarÚintÚstrrÚ	text_typeÚgetvalue)rrÚbodyrr&Úcontent_typerrrÚencode_multipart_formdata?s 

r-)N)Ú
__future__rrÚcodecsr
ÚiorrrÚpackagesrZpackages.sixrÚlookupr$rrr"r-rrrrÚ<module>s