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 #1587: naive_implementation.patch

File naive_implementation.patch, 3.6 KB (added by Felix.Schwarz, 4 years ago)
  • turbogears/startup.py

     
    1111import pkg_resources 
    1212import cherrypy 
    1313from cherrypy import _cputil 
    14 from formencode.variabledecode import NestedVariables 
    1514from cherrypy._cpwsgi import wsgiApp, CPHTTPRequest 
    1615from cherrypy._cpwsgiserver import CherryPyWSGIServer 
    1716 
     
    140139            else: 
    141140                raise cherrypy.NotFound(path) 
    142141 
    143 class NestedVariablesFilter(object): 
    144  
    145     def before_main(self): 
    146         if hasattr(cherrypy.request, "params"): 
    147             cherrypy.request.params = \ 
    148                 NestedVariables.to_python(cherrypy.request.params or {}) 
    149  
    150  
    151142def startTurboGears(): 
    152143    """Handles TurboGears tasks when the CherryPy server starts. 
    153144 
     
    187178    if hasattr(cherrypy, "root") and cherrypy.root: 
    188179        if not hasattr(cherrypy.root, "_cp_filters"): 
    189180            cherrypy.root._cp_filters= [] 
    190         morefilters = [EndTransactionsFilter(), 
    191                        NestedVariablesFilter()] 
     181        morefilters = [EndTransactionsFilter()] 
    192182        if webpath: 
    193183            morefilters.insert(0, VirtualPathFilter()) 
    194184        cherrypy.root._cp_filters.extend(morefilters) 
  • turbogears/controllers.py

     
    66from itertools import izip 
    77import cherrypy 
    88from dispatch import generic, strategy, functions 
     9from formencode.variabledecode import NestedVariables 
    910import turbogears.util as tg_util 
    1011import turbogears 
    1112from inspect import isclass 
     
    331332            "content-type: %s", template, format, allow_json, content_type) 
    332333        if not getattr(func, "exposed", False): 
    333334            def expose(func, *args, **kw): 
     335                kw = NestedVariables.to_python(kw) 
    334336                cherrypy.request.tg_template_enginename = view.base._choose_engine(template)[2] 
    335337                accept = cherrypy.request.headers.get('Accept', "").lower() 
    336338                if not hasattr(func, "_expose"): 
  • turbogears/tests/test_controllers.py

     
    112112        "lastname": validators.String()})(save) 
    113113    save = turbogears.expose()(save) 
    114114 
     115    def echo_values(self, values=[]): 
     116        return ', '.join(map(str, values)) 
     117    echo_values = turbogears.validate(validators={ 
     118        "values": formencode.ForEach(validators.Int())})(echo_values) 
     119    echo_values = turbogears.expose()(echo_values) 
     120 
    115121    class Registration(formencode.Schema): 
    116122        allow_extra_fields = True 
    117123        firstname = validators.String(min=2, not_empty=True) 
     
    382388        testutil.createRequest("/save2?submit=send&firstname=D&lastname=") 
    383389        assert len(cherrypy.root.errors) == 1 
    384390        assert cherrypy.root.errors.has_key("firstname") 
     391         
     392    def test_variabledecode(self): 
     393        "validate decorator calls formencode.variabledecode" 
     394        parameters = {'values-1': '1', 'values-2': '2', 'values-3': '3'} 
     395        items = [] 
     396        for key in parameters: 
     397            items.append(key + "=" + parameters[key]) 
     398        query_string = "&".join(items) 
     399        testutil.createRequest("/echo_values?" + query_string) 
     400        self.assertEqual("1, 2, 3", cherrypy.response.body[0]) 
    385401 
    386402    def test_othertemplate(self): 
    387403        "'tg_html' in a returned dict will use the template specified there"