'Build the body for a multipart/form-data request.
Will successfully encode files when passed as a dict or a list of
2-tuples. Order is retained if data is a list of 2-tuples but abritrary
if parameters are supplied as a dict.'

def _encode_files(self, files):

    if ((not files) or isinstance(self.data, str)):
        return None
    new_fields = []
    fields = to_key_val_list(self.data)
    files = to_key_val_list(files)
    for (field, val) in fields:
        if isinstance(val, list):
            for v in val:
                new_fields.append((field, builtin_str(v)))
        else:
            new_fields.append((field, builtin_str(val)))
    for (k, v) in files:
        if isinstance(v, (tuple, list)):
            (fn, fp) = v
        else:
            fn = (guess_filename(v) or k)
            fp = v
        if isinstance(fp, str):
            fp = StringIO(fp)
        if isinstance(fp, bytes):
            fp = BytesIO(fp)
        new_fields.append((k, (fn, fp.read())))
    (body, content_type) = encode_multipart_formdata(new_fields)
    return (body, content_type)
