On Thu, Dec 9, 2010 at 2:29 PM, Jonathan Gardner
<[email protected]> wrote:
> On Wed, Dec 8, 2010 at 11:02 PM, Mike Orr <[email protected]> wrote:
>> On Wed, Dec 8, 2010 at 10:23 PM, Jonathan Gardner
>> <[email protected]> wrote:
>>> I sometimes use Route's url() to do the query args for me. For instance,
>>>
>>> url('http://google.com', q='aasdf')
>>>
>>> will give me:
>>>
>>> http://google.com?q=aasdf
>>>
>>> which is a very useful shortcut.
>>>
>>> However, I've found that this doesn't work:
>>>
>>> url('http://google.com?q=aasdf', foo='bar')
>>>
>>> which gives me:
>>>
>>> http://google.com?q=aasdf?foo=bar
>>>
>>> Does it make sense to modify Routes to parse the query before it
>>> applies the args in this special case? I can submit a patch.
>>
>> Use ``webhelpers.util.update_params()`` to add/modify query parameters on a
>> URL:
>>
>> update_params("http://google.com/?q=aasdf", foo="bar")
>> update_params("http://google.com/", q="aasdf", foo="bar")
>>
>
> Thanks. Worked like a charm.
>
> One minor issue: update_params returns unicode. Is this significant?
On my computer, it returns Unicode only if the original URL is Unicode:
>>> webhelpers.util.update_params("http://google.com/?q=aasdf", foo="bar")
'http://google.com/?q=aasdf&foo=bar'
>>> webhelpers.util.update_params(u"http://google.com/?q=aasdf", foo="bar")
u'http://google.com/?q=aasdf&foo=bar'
>>> webhelpers.util.update_params("http://google.com/?q=aasdf", foo=u"bar")
'http://google.com/?q=aasdf&foo=bar'
Unicode URLs are invalid, so don't do that. They also aren't
compatible with Routes or url(), although the current version may
stringify url() args for you, I don't remember.
update_params depend only on the Python standard library, and none of
its literals are Unicode, so I think we'll have to accept this as the
normal Python functionality for URLs.
--
Mike Orr <[email protected]>
--
You received this message because you are subscribed to the Google Groups
"pylons-discuss" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/pylons-discuss?hl=en.