#1066: cannot use 'format' as a URL query parameter
----------------------+-----------------------------------------------------
 Reporter:  dalke     |       Owner:  anonymous
     Type:  defect    |      Status:  new      
 Priority:  normal    |   Milestone:           
Component:  CherryPy  |     Version:  0.9a5    
 Severity:  normal    |    Keywords:           
----------------------+-----------------------------------------------------
 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".)

-- 
Ticket URL: <http://trac.turbogears.org/turbogears/ticket/1066>
TurboGears <http://www.turbogears.org/>
TurboGears front-to-back web development
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"TurboGears Tickets" 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-tickets
-~----------~----~----~----~------~----~------~--~---

Reply via email to