File: //snap/core18/current/usr/lib/python3/dist-packages/urllib3/__pycache__/filepost.cpython-36.pyc
3
&�[h� � @ s� d dl mZ d dlZd dlmZ d dlmZ d dlZd dlmZ ddl m
Z
ejd�d Zd
d� Z
dd
� Zdd� Zddd�ZdS )� )�absolute_importN)�uuid4)�BytesIO)�b� )�RequestFieldzutf-8� c C s t � jS )zN
Our embarrassingly-simple replacement for mimetools.choose_boundary.
)r �hex� r
r
�2/usr/lib/python3/dist-packages/urllib3/filepost.py�choose_boundary s r c c sN t | t�rtj| �}nt| �}x*|D ]"}t |t�r:|V q$tj|� V q$W dS )z�
Iterate over fields.
Supports list of (k, v) tuples and dicts, and lists of
:class:`~urllib3.fields.RequestField`.
N)�
isinstance�dict�six� iteritems�iterr Zfrom_tuples)�fields�i�fieldr
r
r �iter_field_objects s
r c C s, t | t�rdd� tj| �D �S dd� | 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.
c s s | ]\}}||fV qd S )Nr
)�.0�k�vr
r
r � <genexpr>6 s ziter_fields.<locals>.<genexpr>c s s | ]\}}||fV qd S )Nr
)r r r r
r
r r 8 s )r
r r r )r r
r
r �iter_fields) s
r c C s� 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 )aJ
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:`mimetools.choose_boundary`.
Nz--%s
s
z--%s--
z multipart/form-data; boundary=%s)r r r �writer �writerZrender_headers�datar
�int�strr Z text_type�getvalue)r �boundaryZbodyr r Zcontent_typer
r
r �encode_multipart_formdata; s
r"