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