MCPcopy
hub / github.com/cherrypy/cherrypy / popargs

Function popargs

cherrypy/_helper.py:55–192  ·  view source on GitHub ↗

Decorate _cp_dispatch. (cherrypy.dispatch.Dispatcher.dispatch_method_name) Optional keyword argument: handler=(Object or Function) Provides a _cp_dispatch function that pops off path segments into cherrypy.request.params under the names specified. The dispatch is then forward

(*args, **kwargs)

Source from the content-addressed store, hash-verified

53
54
55def popargs(*args, **kwargs):
56 """Decorate _cp_dispatch.
57
58 (cherrypy.dispatch.Dispatcher.dispatch_method_name)
59
60 Optional keyword argument: handler=(Object or Function)
61
62 Provides a _cp_dispatch function that pops off path segments into
63 cherrypy.request.params under the names specified. The dispatch
64 is then forwarded on to the next vpath element.
65
66 Note that any existing (and exposed) member function of the class that
67 popargs is applied to will override that value of the argument. For
68 instance, if you have a method named "list" on the class decorated with
69 popargs, then accessing "/list" will call that function instead of popping
70 it off as the requested parameter. This restriction applies to all
71 _cp_dispatch functions. The only way around this restriction is to create
72 a "blank class" whose only function is to provide _cp_dispatch.
73
74 If there are path elements after the arguments, or more arguments
75 are requested than are available in the vpath, then the 'handler'
76 keyword argument specifies the next object to handle the parameterized
77 request. If handler is not specified or is None, then self is used.
78 If handler is a function rather than an instance, then that function
79 will be called with the args specified and the return value from that
80 function used as the next object INSTEAD of adding the parameters to
81 cherrypy.request.args.
82
83 This decorator may be used in one of two ways:
84
85 As a class decorator:
86
87 .. code-block:: python
88
89 @cherrypy.popargs('year', 'month', 'day')
90 class Blog:
91 def index(self, year=None, month=None, day=None):
92 #Process the parameters here; any url like
93 #/, /2009, /2009/12, or /2009/12/31
94 #will fill in the appropriate parameters.
95
96 def create(self):
97 #This link will still be available at /create.
98 #Defined functions take precedence over arguments.
99
100 Or as a member of a class:
101
102 .. code-block:: python
103
104 class Blog:
105 _cp_dispatch = cherrypy.popargs('year', 'month', 'day')
106 #...
107
108 The handler argument may be used to mix arguments with built in functions.
109 For instance, the following setup allows different activities at the
110 day, month, and year level:
111
112 .. code-block:: python

Callers

nothing calls this directly

Calls 2

itemsMethod · 0.80
formatMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…