'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.'

@staticmethod
def _encode_files(files, data):

    if ((not files) or isinstance(data, str)):
        return None
    new_fields = []
    fields = to_key_val_list((data or {}))
    files = to_key_val_list((files or {}))
    for (field, val) in fields:
        if (isinstance(val, basestring) or (not hasattr(val, '__iter__'))):
            val = [val]
        for v in val:
            if (v is not None):
                new_fields.append(((field.decode('utf-8') if isinstance(field, bytes) else field), (v.encode('utf-8') if isinstance(v, str) else v)))
    for (k, v) in files:
        ft = None
        if isinstance(v, (tuple, list)):
            if (len(v) == 2):
                (fn, fp) = v
            else:
                (fn, fp, ft) = v
        else:
            fn = (guess_filename(v) or k)
            fp = v
        if isinstance(fp, str):
            fp = StringIO(fp)
        if isinstance(fp, bytes):
            fp = BytesIO(fp)
        if ft:
            new_v = (fn, fp.read(), ft)
        else:
            new_v = (fn, fp.read())
        new_fields.append((k, new_v))
    (body, content_type) = encode_multipart_formdata(new_fields)
    return (body, content_type)
