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) |
|
|
-
|
|
|
|
| 11 | 11 | import pkg_resources |
| 12 | 12 | import cherrypy |
| 13 | 13 | from cherrypy import _cputil |
| 14 | | from formencode.variabledecode import NestedVariables |
| 15 | 14 | from cherrypy._cpwsgi import wsgiApp, CPHTTPRequest |
| 16 | 15 | from cherrypy._cpwsgiserver import CherryPyWSGIServer |
| 17 | 16 | |
| … |
… |
|
| 140 | 139 | else: |
| 141 | 140 | raise cherrypy.NotFound(path) |
| 142 | 141 | |
| 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 | | |
| 151 | 142 | def startTurboGears(): |
| 152 | 143 | """Handles TurboGears tasks when the CherryPy server starts. |
| 153 | 144 | |
| … |
… |
|
| 187 | 178 | if hasattr(cherrypy, "root") and cherrypy.root: |
| 188 | 179 | if not hasattr(cherrypy.root, "_cp_filters"): |
| 189 | 180 | cherrypy.root._cp_filters= [] |
| 190 | | morefilters = [EndTransactionsFilter(), |
| 191 | | NestedVariablesFilter()] |
| | 181 | morefilters = [EndTransactionsFilter()] |
| 192 | 182 | if webpath: |
| 193 | 183 | morefilters.insert(0, VirtualPathFilter()) |
| 194 | 184 | cherrypy.root._cp_filters.extend(morefilters) |
-
|
|
|
|
| 6 | 6 | from itertools import izip |
| 7 | 7 | import cherrypy |
| 8 | 8 | from dispatch import generic, strategy, functions |
| | 9 | from formencode.variabledecode import NestedVariables |
| 9 | 10 | import turbogears.util as tg_util |
| 10 | 11 | import turbogears |
| 11 | 12 | from inspect import isclass |
| … |
… |
|
| 331 | 332 | "content-type: %s", template, format, allow_json, content_type) |
| 332 | 333 | if not getattr(func, "exposed", False): |
| 333 | 334 | def expose(func, *args, **kw): |
| | 335 | kw = NestedVariables.to_python(kw) |
| 334 | 336 | cherrypy.request.tg_template_enginename = view.base._choose_engine(template)[2] |
| 335 | 337 | accept = cherrypy.request.headers.get('Accept', "").lower() |
| 336 | 338 | if not hasattr(func, "_expose"): |
-
|
|
|
|
| 112 | 112 | "lastname": validators.String()})(save) |
| 113 | 113 | save = turbogears.expose()(save) |
| 114 | 114 | |
| | 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 | |
| 115 | 121 | class Registration(formencode.Schema): |
| 116 | 122 | allow_extra_fields = True |
| 117 | 123 | firstname = validators.String(min=2, not_empty=True) |
| … |
… |
|
| 382 | 388 | testutil.createRequest("/save2?submit=send&firstname=D&lastname=") |
| 383 | 389 | assert len(cherrypy.root.errors) == 1 |
| 384 | 390 | 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]) |
| 385 | 401 | |
| 386 | 402 | def test_othertemplate(self): |
| 387 | 403 | "'tg_html' in a returned dict will use the template specified there" |
Download in other formats: