Warning: Can't synchronize with repository "(default)" (Unsupported version control system "svn": No module named svn). Look in the Trac log for more information.

Ticket #1066 (closed defect: fixed)

Opened 13 years ago

Last modified 12 years ago

[PATCH] cannot use 'format' as a URL query parameter

Reported by: dalke Owned by: anonymous
Priority: normal Milestone:
Component: CherryPy Version: 0.9a5
Severity: normal Keywords:
Cc:

Description

I'm implementing a server against an existing specification which uses "format" as a query parameter. It specifies format of the return document.

I used a controller method starting

    def index(self, assembly, segment=None, start=None, end=None,
              format=None):

This failed with a traceback ending

File "/home/dalke/local/lib/python2.4/site-packages/TurboGears-1.1a0-py2.4.egg/turbogears/controllers.py", line 298, in <lambda>
    mapping, fragment, *args, **kw)))
TypeError: _execute_func() got multiple values for keyword argument 'format'

The calling code is

            rulefunc = lambda _func, accept, allow_json,
                    *args, **kw: 
                    _execute_func(_func, template, format, content_type,
                                mapping, fragment, *args, **kw)))

and the _execute_func is

def _execute_func(func, template, format, content_type, mapping, fragment, *args
, **kw):

This obviously rejects any URL query parameters with the name "func", "template", "format", .... (For a real fun one, pass in "self" in the URL query parameter!)

The code is easy to fix -- pass args and kw as a list and dictionary rather than flattening them into the call.

Index: controllers.py
===================================================================
--- controllers.py	(revision 1710)
+++ controllers.py	(working copy)
@@ -215,7 +215,7 @@
             ' =="text/javascript")')(
             lambda _func, accept, allow_json, 
                 *args, **kw: _execute_func(
-                    _func, "json", None, None, None, False, *args, **kw))
+                    _func, "json", None, None, None, False, args, kw))
         
     found_default = False
     for ruleinfo in func._ruleinfo:
@@ -295,7 +295,7 @@
             rulefunc = lambda _func, accept, allow_json,
                     *args, **kw: 
                     _execute_func(_func, template, format, content_type,
-                                mapping, fragment, *args, **kw)))
+                                mapping, fragment, args, kw)))
             
         if allow_json:
             func._allow_json = True
@@ -312,7 +312,7 @@
         return expose
     return weak_signature_decorator(entangle)
 
-def _execute_func(func, template, format, content_type, mapping, fragment, *args, **kw):
+def _execute_func(func, template, format, content_type, mapping, fragment, args, kw):
     """Call controller method and process it's output."""
     if turbogears.config.get("tg.strict_parameters", False):
 	    tg_util.remove_keys(kw, ["tg_random", "tg_format"])

(BTW, in the docstring for '_execute_func' it should use "its" and not "it's".)

Attachments

controllers.py.diff Download (1.3 KB) - added by dalke 13 years ago.
[PATCH] to controllers.py

Change History

comment:1 Changed 13 years ago by alberto

Hi, Could you please post the patch as an attachment to this ticket? It's much easier to apply that way :)

Make sure to prepend the title with [PATCH] so it shows up in the "pending patches" report and get the best chance to be seen by a reviewer/committer.

Thanks :) Alberto

Changed 13 years ago by dalke

[PATCH] to controllers.py

comment:2 Changed 13 years ago by dalke

  • Summary changed from cannot use 'format' as a URL query parameter to [PATCH] cannot use 'format' as a URL query parameter

I'm assuming you mean the title of the bug report and not the file description.... I did both just in case.

comment:3 Changed 13 years ago by alberto

  • Status changed from new to closed
  • Resolution set to fixed

Comitted at [1803]. Thanks!

Note: See TracTickets for help on using tickets.