def _encode_multipart_formdata(self, fields):
        """
        Based on Wade Leftwich's function:
        http://code.activestate.com/recipes/146306/
        """
        #use a random boundary that does not appear in the fields
        boundary = ''
        while boundary in ''.join(fields):
            boundary = os.urandom(16).encode('hex')
        L = []
        for i in fields:
            L.append('--' + boundary)
            L.append('Content-Disposition: form-data; name="%s"' % i)
            L.append('')
            L.append(fields[i])
        L.append('--' + boundary + '--')
        L.append('')
        body = '\r\n'.join(L)
        content_type = 'multipart/form-data; boundary=%s' % boundary
        header = {'Content-Type':content_type}
        return header, body
dataset/ETHPy150Open secondstory/dewpoint/libcloud/drivers/ecp.py/ECPConnection._encode_multipart_formdata/original