def urlencode_unicode(data, doseq=<NUM_LIT:0>):
data_iter = None<EOL>if isdict(data):<EOL><INDENT>data_iter = list(data.items())<EOL><DEDENT>elif islist(data):<EOL><INDENT>data_iter = data<EOL><DEDENT>if data_iter:<EOL><INDENT>for i, (key, value) in enumerate(data_iter):<EOL><INDENT>if isinstance(value, text_type):<EOL><INDENT>try:<EOL><INDENT>safe_val = str(value)<EOL><DEDENT>except UnicodeEncodeError:<EOL><INDENT>safe_val = value.encode('<STR_LIT:utf-8>')<EOL><DEDENT>finally:<EOL><INDENT>if isdict(data):<EOL><INDENT>data[key] = safe_val<EOL><DEDENT>else:<EOL><INDENT>data[i] = (key, safe_val)<EOL><DEDENT><DEDENT><DEDENT><DEDENT><DEDENT>return urlencode(data, doseq=doseq)<EOL>
urllib.urlencode can't handle unicode, this is a hack to fix it.