Creating decorator that modifies _cp_dispatch

Adam Baxter <[email protected]> Sun, 23 Jun 2019 06:53:47 -0700 (PDT)
Newsgroups gmane.comp.python.cherrypy
Message-ID <[email protected]>
------=_Part_1336_290277821.1561298027050
Content-Type: multipart/alternative; 
	boundary="----=_Part_1337_1507832269.1561298027050"

------=_Part_1337_1507832269.1561298027050
Content-Type: text/plain; charset="UTF-8"

Hi,
Perhaps I'm thinking about this the wrong way, but I can't seem to work out 
how I'd make a decorator like cherrypy.expose, except for modifying the way 
dispatch works.

What I'd like to do is implement an explicit decorator that 
/maps/path/segments to variables

@from_path("some","variable","here")
def my_function(*args,**kwargs):
   #if I GET /my_function/one/two/three
   #kwargs would be: {'some': 'one', 'variable': 'two', 'here': 'three'} 

but I can't figure out what I need to pass back to the "pipeline" for 
cherrypy to keep working correctly.

Thanks,
Adam

-- 
You received this message because you are subscribed to the Google Groups "cherrypy-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cherrypy-users+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/[email protected]
To post to this group, send email to cherrypy-users-/JYPxA39Uh5TLH3MbocFF+G/[email protected]
Visit this group at https://groups.google.com/group/cherrypy-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/cherrypy-users/69b04f8b-99ae-4846-8489-77e0a37b2ce9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

------=_Part_1337_1507832269.1561298027050
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><div>Hi,</div><div>Perhaps I&#39;m thinking about this the=
 wrong way, but I can&#39;t seem to work out how I&#39;d make a decorator l=
ike cherrypy.expose, except for modifying the way dispatch works.</div><div=
><br></div><div>What I&#39;d like to do is implement an explicit decorator =
that /maps/path/segments to variables</div><div><div style=3D"background-co=
lor: rgb(250, 250, 250); border-color: rgb(187, 187, 187); border-style: so=
lid; border-width: 1px; overflow-wrap: break-word;" class=3D"prettyprint"><=
code class=3D"prettyprint"><div class=3D"subprettyprint"><div style=3D"colo=
r: #d4d4d4;background-color: #1e1e1e;font-family: Consolas, &#39;Courier Ne=
w&#39;, monospace;font-weight: normal;font-size: 14px;line-height: 19px;whi=
te-space: pre;"><span style=3D"color: #000;" class=3D"styled-by-prettify"><=
br></span><div><span style=3D"color: #dcdcaa;"><span style=3D"color: #066;"=
 class=3D"styled-by-prettify">@from_path</span></span><span style=3D"color:=
 #d4d4d4;"><span style=3D"color: #660;" class=3D"styled-by-prettify">(</spa=
n></span><span style=3D"color: #ce9178;"><span style=3D"color: #080;" class=
=3D"styled-by-prettify">&quot;some&quot;</span></span><span style=3D"color:=
 #d4d4d4;"><span style=3D"color: #660;" class=3D"styled-by-prettify">,</spa=
n></span><span style=3D"color: #ce9178;"><span style=3D"color: #080;" class=
=3D"styled-by-prettify">&quot;variable&quot;</span></span><span style=3D"co=
lor: #d4d4d4;"><span style=3D"color: #660;" class=3D"styled-by-prettify">,<=
/span></span><span style=3D"color: #ce9178;"><span style=3D"color: #080;" c=
lass=3D"styled-by-prettify">&quot;here&quot;</span></span><span style=3D"co=
lor: #d4d4d4;"><span style=3D"color: #660;" class=3D"styled-by-prettify">)<=
/span></span></div><div><span style=3D"color: #569cd6;"><span style=3D"colo=
r: #008;" class=3D"styled-by-prettify">def</span></span><span style=3D"colo=
r: #d4d4d4;"><span style=3D"color: #000;" class=3D"styled-by-prettify"> </s=
pan></span><span style=3D"color: #dcdcaa;"><span style=3D"color: #000;" cla=
ss=3D"styled-by-prettify">my_function</span></span><span style=3D"color: #d=
4d4d4;"><span style=3D"color: #660;" class=3D"styled-by-prettify">(</span><=
/span><span style=3D"color: #d4d4d4;"><span style=3D"color: #660;" class=3D=
"styled-by-prettify">*</span></span><span style=3D"color: #9cdcfe;"><span s=
tyle=3D"color: #000;" class=3D"styled-by-prettify">args</span></span><span =
style=3D"color: #d4d4d4;"><span style=3D"color: #660;" class=3D"styled-by-p=
rettify">,</span></span><span style=3D"color: #d4d4d4;"><span style=3D"colo=
r: #660;" class=3D"styled-by-prettify">**</span></span><span style=3D"color=
: #9cdcfe;"><span style=3D"color: #000;" class=3D"styled-by-prettify">kwarg=
s</span></span><span style=3D"color: #d4d4d4;"><span style=3D"color: #660;"=
 class=3D"styled-by-prettify">):</span></span></div><div><span style=3D"col=
or: #d4d4d4;"><span style=3D"color: #000;" class=3D"styled-by-prettify"> =
=C2=A0 =C2=A0</span></span><span style=3D"color: #6a9955;"><span style=3D"c=
olor: #800;" class=3D"styled-by-prettify">#if I GET /my_function/one/two/th=
ree</span></span></div><div><span style=3D"color: #d4d4d4;"><span style=3D"=
color: #800;" class=3D"styled-by-prettify"> =C2=A0 =C2=A0</span></span><spa=
n style=3D"color: #6a9955;"><span style=3D"color: #800;" class=3D"styled-by=
-prettify">#kwargs would be: {&#39;some&#39;: &#39;one&#39;, &#39;variable&=
#39;: &#39;two&#39;, &#39;here&#39;: &#39;three&#39;} </span></span></div><=
/div></div></code></div><br></div><div>but I can&#39;t figure out what I ne=
ed to pass back to the &quot;pipeline&quot; for cherrypy to keep working co=
rrectly.</div><div><br></div><div>Thanks,</div><div>Adam<br></div></div>

<p></p>

-- <br />
You received this message because you are subscribed to the Google Groups &=
quot;cherrypy-users&quot; group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:cherrypy-users+unsubscribe-/[email protected]">cher=
rypy-users+unsubscribe-/[email protected]</a>.<br />
To post to this group, send email to <a href=3D"mailto:cherrypy-users@googl=
egroups.com">cherrypy-users-/[email protected]</a>.<br />
Visit this group at <a href=3D"https://groups.google.com/group/cherrypy-use=
rs">https://groups.google.com/group/cherrypy-users</a>.<br />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/d/msgid/cherrypy-users/69b04f8b-99ae-4846-8489-77e0a37b2ce9%40googlegrou=
ps.com?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.com/d/=
msgid/cherrypy-users/69b04f8b-99ae-4846-8489-77e0a37b2ce9%40googlegroups.co=
m</a>.<br />
For more options, visit <a href=3D"https://groups.google.com/d/optout">http=
s://groups.google.com/d/optout</a>.<br />

------=_Part_1337_1507832269.1561298027050--

------=_Part_1336_290277821.1561298027050--