@staticmethod<EOL><INDENT>def _encode_params(data):<DEDENT>
if isinstance(data, (str, bytes)):<EOL><INDENT>return data<EOL><DEDENT>elif hasattr(data, '<STR_LIT>'):<EOL><INDENT>return data<EOL><DEDENT>elif hasattr(data, '<STR_LIT>'):<EOL><INDENT>result = []<EOL>for k, vs in to_key_val_list(data):<EOL><INDENT>if isinstance(vs, basestring) or not hasattr(vs, '<STR_LIT>'):<EOL><INDENT>vs = [vs]<EOL><DEDENT>for v in vs:<EOL><INDENT>if v is not None:<EOL><INDENT>result.append(<EOL>(k.encode('<STR_LIT:utf-8>') if isinstance(k, str) else k,<EOL>v.encode('<STR_LIT:utf-8>') if isinstance(v, str) else v))<EOL><DEDENT><DEDENT><DEDENT>return urlencode(result, doseq=True)<EOL><DEDENT>else:<EOL><INDENT>return data<EOL><DEDENT>
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 arbitrary
        if parameters are supplied as a dict.