[Python-ideas] Proposed addtion to urllib.parse in 3.1 (and urlparse in 2.7)

Eric Smith eric at trueblade.com
Fri Mar 27 19:54:56 CET 2009


Arnaud Delobelle wrote:
> 
> On 27 Mar 2009, at 16:17, Mart Sõmermaa wrote:
> 
>> On Fri, Mar 27, 2009 at 6:13 PM, Bill Janssen <janssen at parc.com> wrote:
>> Mart Sõmermaa <mrts.pydev at gmail.com> wrote:
>>
>> > Appending query parameters to a URL is a very common need. However, 
>> there's
>> > nothing in urllib.parse (and older urlparse) that caters for that need.
>> >
>> > Therefore, I propose adding the following to 2.7 and 3.1 in the 
>> respective
>> > libs:
>>
>> >     >>> add_query_params('http://foo.com?a=b', b='c', d='q')
>>
>> To begin with, I wouldn't use keyword params.  They're syntactically
>> more restrictive than the rules for application/x-www-form-urlencoded
>> allow, so you start by ruling out whole classes of URLs.
>>
>> Bill
>>
>> Valid point, using an ordinary dict instead would resolve that (i.e. 
>> def add_query_params(url, param_dict)).
> 
> Note that it's still not general enough as query fields can be repeated, 
> e.g.
> 
>     http://foo.com/search/?q=spam&q=eggs
>

It's also possible that the order matters. I think an iterable of tuples 
(such as returned by dict.items(), but any iterable will do) would be an 
okay interface.



More information about the Python-ideas mailing list