[Python-Dev] Should urlencode() sort the query parameters (if they come from a dict)?

Joao S. O. Bueno jsbueno at python.org.br
Sat Aug 18 00:28:15 CEST 2012


On 17 August 2012 18:52, Chris Angelico <rosuav at gmail.com> wrote:
> On Sat, Aug 18, 2012 at 5:27 AM, Guido van Rossum <guido at python.org> wrote:
>> I just fixed a unittest for some code used at Google that was
>> comparing a url generated by urllib.encode() to a fixed string. The
>> problem was caused by turning on PYTHONHASHSEED=1. Because of this,
>> the code under test would generate a textually different URL each time
>> the test was run, but the intention of the test was just to check that
>> all the query parameters were present and equal to the expected
>> values.
>>
>>
>>         query = sorted(query.items())
>
> Hmm. ISTM this is putting priority on the unit test above the
> functionality of actual usage. Although on the other hand, sorting
> parameters on a URL is nothing compared to the cost of network
> traffic, so it's unlikely to be significant.
>

I don't think this behavior is only desirable to unit tests: having
URL's been formed in predictable way  a good thing in any way one
thinks about it.

   js
  -><-

> Chris Angelico
>


More information about the Python-Dev mailing list