I think this is much better, but still think that this is a compromise
where no compromise is necessary. I had support for the same thing in
my decorator -- but it turned out I never needed to use it so I took
it out. It seems entirely possible to me that you're overestimating
the hassle associated with having to use a separate method in cases
when you need additional arguments etc.
(BTW, I think with this change checks for .wsgi_app in get_response in
dec branch can be taken out as well)
Sure. I'd prefer to use components written with this dual-interface
decorator to the one proposed before, however I'm pretty sure I'll
stick to webob_wrap for my own stuff simply because I like *not*
having any features that wsgify adds. Simpler stuff makes thinking
about things easier and having so many ways to generate response seems
to encourage messy code (reminds me of pyzen). So what I'm saying is
that I'm glad it would be easier to use stuff as WSGI without knowing
anything else about it, and that's all that matters to me at this
point, so agreement reached. :)
BTW, I wonder if you will be taking the wsgify.reverse out?
> >
> > (BTW, I think with this change checks for .wsgi_app in get_response in
> > dec branch can be taken out as well)
> >
> >
> >
> >
>
> Yeah, I made that change locally but I have some mess I need to straighten
> before I commit.
>
> Ian
>
>
>
On Tue, Jun 2, 2009 at 1:07 AM, Ian Bicking <ia...@colorstudy.com> wrote:will this except clause work for Python 2.4? Sad that I have to ask.
> Is there anything really wrong about a decorator that looks roughly like
> this?
>
> def wsgify(func):
> def replacement(req, *args, **kw):
> if type(req) is dict:
> environ = req
> req = Request(environ)
> start_response = args[0]
> try:
> resp = func(req)
> except exc.HTTPException, resp:
import webob
@webob.Request.application
def myapp(req):
return webob.Response(...)
Any thoughts on this? Request is of course a pretty big class
already, but then as a result this isn't proportionally much of an
increase in size ;) Middleware would work the same way.
Ian
Cons: It looks a bit ugly when no subclass is needed, "request
application" doesn't sound right and subclassing the decorator itself
is harder this way.
Overall I think these things deserve to be in their own / global namespace.
Also, nothing wrong with @wsgify(Request2) IMO.