def urlencode3(query, doseq=False, safe="<STR_LIT>", encoding=None, errors=None,<EOL>quote_via=quote_plus, querydelimiter="<STR_LIT:&>"):
if hasattr(query, "<STR_LIT>"):<EOL><INDENT>query = query.items()<EOL><DEDENT>else:<EOL><INDENT>try:<EOL><INDENT>if len(query) and not isinstance(query[<NUM_LIT:0>], tuple):<EOL><INDENT>raise TypeError<EOL><DEDENT><DEDENT>except TypeError:<EOL><INDENT>ty, va, tb = sys.exc_info()<EOL>raise TypeError("<STR_LIT>"<EOL>"<STR_LIT>").with_traceback(tb)<EOL><DEDENT><DEDENT>l = []<EOL>if not doseq:<EOL><INDENT>for k, v in query:<EOL><INDENT>if isinstance(k, bytes):<EOL><INDENT>k = quote_via(k, safe)<EOL><DEDENT>else:<EOL><INDENT>k = quote_via(str(k), safe, encoding, errors)<EOL><DEDENT>if isinstance(v, bytes):<EOL><INDENT>v = quote_via(v, safe)<EOL><DEDENT>else:<EOL><INDENT>v = quote_via(str(v), safe, encoding, errors)<EOL><DEDENT>l.append(k + '<STR_LIT:=>' + v)<EOL><DEDENT><DEDENT>else:<EOL><INDENT>for k, v in query:<EOL><INDENT>if isinstance(k, bytes):<EOL><INDENT>k = quote_via(k, safe)<EOL><DEDENT>else:<EOL><INDENT>k = quote_via(str(k), safe, encoding, errors)<EOL><DEDENT>if isinstance(v, bytes):<EOL><INDENT>v = quote_via(v, safe)<EOL>l.append(k + '<STR_LIT:=>' + v)<EOL><DEDENT>elif isinstance(v, str):<EOL><INDENT>v = quote_via(v, safe, encoding, errors)<EOL>l.append(k + '<STR_LIT:=>' + v)<EOL><DEDENT>else:<EOL><INDENT>try:<EOL><INDENT>x = len(v)<EOL><DEDENT>except TypeError:<EOL><INDENT>v = quote_via(str(v), safe, encoding, errors)<EOL>l.append(k + '<STR_LIT:=>' + v)<EOL><DEDENT>else:<EOL><INDENT>for elt in v:<EOL><INDENT>if isinstance(elt, bytes):<EOL><INDENT>elt = quote_via(elt, safe)<EOL><DEDENT>else:<EOL><INDENT>elt = quote_via(str(elt), safe, encoding, errors)<EOL><DEDENT>l.append(k + '<STR_LIT:=>' + elt)<EOL><DEDENT><DEDENT><DEDENT><DEDENT><DEDENT>return querydelimiter.join(l)<EOL>
Encode a dict or sequence of two-element tuples into a URL query string.

    If any values in the query arg are sequences and doseq is true, each
    sequence element is converted to a separate parameter.

    If the query arg is a sequence of two-element tuples, the order of the
    parameters in the output will match the order of parameters in the
    input.

    The components of a query arg may each be either a string or a bytes type.

    The safe, encoding, and errors parameters are passed down to the function
    specified by quote_via (encoding and errors only if a component is a str).