def encode_multipart(vars, files=None, boundary=None):
    """
    Encode a set of variables and/or files into a ``multipart/form-data``
    request body, and returns a list of strings and files that can be sent to
    the server, along with the used boundary.

    =========  ============
    Argument   Description
    =========  ============
    vars       A dictionary of variables to encode.
    files      *Optional.* A dictionary of tuples of ``(filename, data)`` to encode.
    boundary   *Optional.* The boundary string to use when encoding, if for any reason the default string is unacceptable.
    =========  ============
    """

    if boundary is None:
        boundary = '-----pants-----PANTS-----pants$'

    out = []

    for k, v in vars.iteritems():
        out.append('--%s%sContent-Disposition: form-data; name="%s"%s%s%s' % (boundary, CRLF, k, DOUBLE_CRLF, v, CRLF))
    if files:
        for k, v in files.iteritems():
            if isinstance(v, (list,tuple)):
                fn, v = v
            else:
                fn = get_filename(v)
                if not fn:
                    fn = k

            out.append('--%s%sContent-Disposition: form-data; name="%s"; filename="%s"%sContent-Type: %s%sContent-Transfer-Encoding: binary%s' % (boundary, CRLF, k, fn, CRLF, content_type(fn), CRLF, DOUBLE_CRLF))
            out.append(v)
            out.append(CRLF)

    out.append('--%s--%s' % (boundary, CRLF))

    return boundary, out
dataset/ETHPy150Open ecdavis/pants/pants/http/utils.py/encode_multipart/original