human
Write me a the Python program you requested given the following:
Complete the below
def encode_multipart_formdata(fields, files):

    ''''Encode form data (``fields``) and ``files`` for POST request.
    :param fields: mapping of ``{name : value}`` pairs for normal form fields.
    :type fields: :class:`dict`
    :param files: dictionary of fieldnames/files elements for file data.
    See below for details.
    :type files: :class:`dict` of :class:`dicts`
    :returns: ``(headers, body)`` ``headers`` is a :class:`dict` of HTTP headers
    :rtype: 2-tuple ``(dict, str)``
    The ``files`` argument is a dictionary::
    {\'fieldname\' : { \'filename\': \'blah.txt\',
    \'content\': \'<binary data>\',
    \'mimetype\': \'text/plain\'}
    - ``fieldname`` is the name of the field in the HTML form.
    - ``mimetype`` is optional. If not provided, :mod:`mimetypes` will be used to guess the mimetype, or ``application/octet-stream`` will be used.'
    '''
assistant
#Here is the Python program you requested.
    def get_content_type(filename):
        'Return    or    guess    mimetype    of    ``filename``.\n\n                                :param    filename:    filename    of    file\n                                :type    filename:    unicode/string\n                                :returns:    mime-type,    e.g.    ``text/html``\n                                :rtype:    :class::class:`str`\n\n                                '
        return (mimetypes.guess_type(filename)[0] or 'application/octet-stream')
    boundary = ('-----' + ''.join((random.choice(BOUNDARY_CHARS) for i in range(30))))
    CRLF = '\r\n'
    output = []
    for (name, value) in fields.items():
        if isinstance(name, unicode):
            name = name.encode('utf-8')
        if isinstance(value, unicode):
            value = value.encode('utf-8')
        output.append(('--' + boundary))
        output.append(('Content-Disposition:    form-data;    name="%s"' % name))
        output.append('')
        output.append(value)
    for (name, d) in files.items():
        filename = d[u'filename']
        content = d[u'content']
        if (u'mimetype' in d):
            mimetype = d[u'mimetype']
        else:
            mimetype = get_content_type(filename)
        if isinstance(name, unicode):
            name = name.encode('utf-8')
        if isinstance(filename, unicode):
            filename = filename.encode('utf-8')
        if isinstance(mimetype, unicode):
            mimetype = mimetype.encode('utf-8')
        output.append(('--' + boundary))
        output.append(('Content-Disposition:    form-data;    name="%s";    filename="%s"' % (name, filename)))
        output.append(('Content-Type:    %s' % mimetype))
        output.append('')
        output.append(content)
    output.append((('--' + boundary) + '--'))
    output.append('')
    body = CRLF.join(output)
    headers = {'Content-Type': ('multipart/form-data;    boundary=%s' % boundary), 'Content-Length': str(len(body))}
    return (headers, body)