

def encode_multipart_formdata(fields, files):

    def get_content_type(filename):
        return (mimetypes.guess_type(filename)[0] or 'application/octet-stream')
    LIMIT = ('----------' + uuid.uuid4().hex)
    CRLF = '\r\n'
    L = []
    for (key, value) in fields:
        L.append(('--' + LIMIT))
        L.append(('Content-Disposition: form-data; name="%s"' % key))
        L.append('')
        L.append(value)
    for (key, filename, value) in files:
        L.append(('--' + LIMIT))
        L.append(('Content-Disposition: form-data; name="%s"; filename="%s"' % (key, filename)))
        L.append(('Content-Type: %s' % get_content_type(files)))
        L.append('')
        L.append(value)
    L.append((('--' + LIMIT) + '--'))
    L.append('')
    body = CRLF.join(L)
    content_type = ('multipart/form-data; boundary=%s' % LIMIT)
    return (content_type, body)

dataset/ETHPy150Open yukuku/telebot/multipart.py encode_multipart_formdata/VarMisuse@156/223 `filename`->`files`