

def encode_multipart_data(self):

    def encode(data):
        if isinstance(data, text_type):
            data = data.encode('utf-8')
        return data
    boundary = choose_boundary()
    body = BytesIO()
    for (key, value) in self.data.items():
        body.write(encode(('--%s\r\n' % boundary)))
        body.write(encode(('Content-Disposition: form-data; name="%s"' % key)))
        body.write(encode((('\r\n\r\n' + str(value)) + '\r\n')))
    for _file in self.files:
        body.write(encode(('--%s\r\n' % boundary)))
        body.write(encode(('Content-Disposition: form-data; name="file"; filename="%s"\r\n' % _file)))
        body.write(encode((('Content-Type: %s\r\n' % mimetypes.guess_type(_file)[0]) or 'application/octet-stream')))
        body.write(encode('\r\n'))
        try:
            with open(_file, 'rb') as f:
                data = f.read()
                body.write(encode(data))
        except IOError:
            raise
        body.write(encode('\r\n'))
    body.write(encode(('--%s--\r\n\r\n' % boundary)))
    content_type = ('multipart/form-data; boundary=%s' % boundary)
    return (content_type, body.getvalue())

dataset/ETHPy150Open smsapi/smsapi-python-client/smsapi/proxy.py ApiHttpProxy.encode_multipart_data/original