def _encode_params(**kwargs):
args = []<EOL>for k, v in kwargs.iteritems():<EOL><INDENT>if isinstance(v, basestring):<EOL><INDENT>qv = v.encode('<STR_LIT:utf-8>') if isinstance(v, unicode) else v<EOL>args.append('<STR_LIT>' % (k, urllib.quote(qv, SAFE_URL_CARS)))<EOL><DEDENT>elif isinstance(v, collections.Iterable):<EOL><INDENT>for i in v:<EOL><INDENT>qv = i.encode('<STR_LIT:utf-8>') if isinstance(i, unicode) else str(i)<EOL>args.append('<STR_LIT>' % (k, urllib.quote(qv, SAFE_URL_CARS)))<EOL><DEDENT><DEDENT>else:<EOL><INDENT>qv = str(v)<EOL>args.append('<STR_LIT>' % (k, urllib.quote(qv, SAFE_URL_CARS)))<EOL><DEDENT><DEDENT>return '<STR_LIT:&>'.join(args)<EOL>
Do url-encode parameters

>>> _encode_params(a=1, b='R&D')
'a=1&b=R%26D'
>>> _encode_params(a=u'\u4e2d\u6587', b=['A', 'B', 123])
'a=%E4%B8%AD%E6%96%87&b=A&b=B&b=123'