'Encode parameters in a piece of data.
Will successfully encode parameters 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_params(data):

    if isinstance(data, (str, bytes)):
        return data
    elif hasattr(data, 'read'):
        return data
    elif hasattr(data, '__iter__'):
        result = []
        for (k, vs) in to_key_val_list(data):
            for v in ((isinstance(vs, list) and vs) or [vs]):
                if (v is not None):
                    result.append(((k.encode('utf-8') if isinstance(k, str) else k), (v.encode('utf-8') if isinstance(v, str) else v)))
        return urlencode(result, doseq=True)
    else:
        return data
