Hi,

Thanks for the replise. I tried the function given and also
cgi.parse_qs. Unfortunatley it only works partially. The expected
behaviour like the way turbogear sees it is not the same. I realized i
dont need args parsing, just kw is fine. But both above args dont do
it fully like TG does.

For example for a query like:
a=1&b=2&c.0.1=3&c.0.2=4&c.1.1=5&c.1.2=6&d.0=arg1&d.0=arg2

Turbogears gets this kw argument as:

kw =
{'a': '1',
 'b': '2',
 'c': {'1': {'1': '5', '2': '6'}, '0': {'1': '3', '2': '4'}},
 'd': {'0': ['arg1', 'arg2']}}

This is what i would like to decode my string into, so i can pass this
argument to the widget.render. Does anyone know how to achieve this
with fully feature? note how the multiple nested dicts and arrays
work. This isn't simply about parsing a=1&b=2, etc... The above
structure is very nice and organized so i can specify a range of
parameters to my apps.

thanks.

-tml


On Apr 4, 8:24 am, "fumanchu" <[EMAIL PROTECTED]> wrote:
> tml wrote:
> > Anyone know how I can take a url like this:
>
> >http://domain/loc/widget?id=1&j.0.0=tom&j.0.1=jerry&k=hello&f.0=woo&f...
>
> > and convert that into a (arg, kw) pair like cherrypy does when calling
> > the corresponding controller argument?
>
> > I'm trying to render the widget internally based on the url keywords,
> > so I would like to call a the widget's function, but I can't pass it
> > the url string as is.
>
> The **kwargs part is easy (even easier if you don't care about image
> maps):
>
> image_map_pattern = re.compile(r"[0-9]+,[0-9]+")
>
> def parse_query_string(query_string, keep_blank_values=True):
>     """Build a params dictionary from a query_string."""
>     if image_map_pattern.match(query_string):
>         # Server-side image map. Map the coords to 'x' and 'y'
>         # (like CGI::Request does).
>         pm = query_string.split(",")
>         pm = {'x': int(pm[0]), 'y': int(pm[1])}
>     else:
>         pm = cgi.parse_qs(query_string, keep_blank_values)
>         for key, val in pm.items():
>             if len(val) == 1:
>                 pm[key] = val[0]
>     return pm
>
> The *args part is very nasty and depends on the arrangement of your
> controllers. But you might be able to use mapPathToObject (CP 2.1; for
> CP 2.2 use cherrypy.request.mapPathToObject) to find which exposed
> callable will be used.
>
> Robert Brewer
> System Architect
> Amor Ministries
> [EMAIL PROTECTED]


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"TurboGears" 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/turbogears?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to