[Chicago] Python 3.0 urllib.parse.urlencode()
Dan Mahn
dan.mahn at digidescorp.com
Thu Feb 26 18:17:56 CET 2009
Hello,
I'm writing a test suite that uses URLs and HTTP requests.
I would like to use a 'latin-1' for encoding some of the query string
information. I noticed in the Python 3.0 library documentation that
urllib.parse.quote_plus() allows me to send "bytes". When I use
quote_plus() directly, I can encode my string in my choice of encodings
(i.e. "latin-1") and send the resulting bytes to quote_plus(), and it
does exactly what I expect.
Considering quote_plus() takes "bytes", I expected urlencode() to allow
the same, but it does not. However, with a slight modification, it can.
For instance (I am using doseq=0):
changing:
v = quote_plus(str(v))
to ...
if isinstance(v, bytes):
v = quote_plus(v)
else:
v = quote_plus(str(v))
Produces the result I would expect.
Does this seem like something that has been overlooked, and should be
the default behavior? Python 3.0 has introduced some changes in the
APIs here, and this appears to affect functionality that is unique to 3.0.
Additionally, it would seem to me that urlencode() itself should take an
"encoding" parameter, and possibly other parameters, that would be
passed on to quote_plus(). However, that could be worked around as long
as urlencode() could use "bytes", as above. (Actually, the above ought
to be extended to "k", as well as the "doseq" side of the if.)
More information about the Chicago
mailing list