Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
WSGI environ
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  Messages 26 - 29 of 29 - Collapse all  -  Translate all to Translated (View all originals) < Older 
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Robert Brewer  
View profile  
 More options Feb 3 2006, 4:18 pm
From: "Robert Brewer" <fuman...@amor.org>
Date: Fri, 3 Feb 2006 13:18:25 -0800
Local: Fri, Feb 3 2006 4:18 pm
Subject: Re: WSGI environ

Christian wrote:
> SCRIPT_NAME = '/apps/cherrypy' #the path to the CP wsgiApp
> PATH_INFO = '/projectapp/tags/filters'

and I countered with:

> The problem here is that you should expect:

>     SCRIPT_NAME = '/apps/cherrypy/projectapp'
>     PATH_INFO = '/tags/filters'

to which Christian answered:

> ...the way I understood it, SCRIPT_NAME is the path up to the
> wsgiApp callable.  '/projectapp/tags/filters' is a path to a
> "sub-app" hosted within the CP wsgiApp that is dispatched by CP.

Phillip J. Eby wrote on web-...@python.org (in a different discussion):

IMO, Phillip's comments add support for my interpretation of SCRIPT_NAME
(as it relates to CherryPy): that it's perfectly OK for SCRIPT_NAME to
be something other than "the path up to the wsgiApp callable". When I
wrote wsgiApp, it was designed to be completely independent of the URL:
one callable for multiple "WSGI apps"; each "CP app", when invoked via
_cpwsgi, equates to one "WSGI app". I can see now that I should not have
called it "wsgiApp". :(

PEP 333 takes pains to say "the application object" or "the application
callable" in many, many places where it could have just said "the
application"--I think there's a reason, and it is that "the callable" is
supposed to be decoupled from "the application". One common way to
implement that for a framework is to make "the callable" a factory
function which returns "the real callable"; I chose in CP to use
polymorphism ("many apps -> one function") rather than use a factory
("many apps -> one function -> many functions").

/soapbox off ;)

Robert Brewer
System Architect
Amor Ministries
fuman...@amor.org


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Christian Wyglendowski  
View profile  
 More options Feb 3 2006, 5:08 pm
From: Christian Wyglendowski <christ...@dowski.com>
Date: Fri, 03 Feb 2006 16:08:49 -0600
Local: Fri, Feb 3 2006 5:08 pm
Subject: Re: [cherrypy-devel] Re: WSGI environ
at some point I said:

>> SCRIPT_NAME = '/apps/cherrypy' #the path to the CP wsgiApp
>> PATH_INFO = '/projectapp/tags/filters'

and Robert countered:

>> The problem here is that you should expect:

>>     SCRIPT_NAME = '/apps/cherrypy/projectapp'
>>     PATH_INFO = '/tags/filters'

then I answered:

>> ...the way I understood it, SCRIPT_NAME is the path up to the
>> wsgiApp callable.  '/projectapp/tags/filters' is a path to a
>> "sub-app" hosted within the CP wsgiApp that is dispatched by CP.

then Phillip J. Eby wrote on web-...@python.org (in a different discussion):

which Robert followed with:

> IMO, Phillip's comments add support for my interpretation of SCRIPT_NAME
> (as it relates to CherryPy): that it's perfectly OK for SCRIPT_NAME to
> be something other than "the path up to the wsgiApp callable". When I
> wrote wsgiApp, it was designed to be completely independent of the URL:
> one callable for multiple "WSGI apps"; each "CP app", when invoked via
> _cpwsgi, equates to one "WSGI app". I can see now that I should not have
> called it "wsgiApp". :(

I've been following that web-sig discussion as well, and maybe I'm wrong
here, but I think he is referring to changing SCRIPT_NAME within a
wsgiApp for the benefit of a hosted wsgiApp.  And that is totally cool.
  Once we are inside of the CP dispatch process, if it can determine
that "projectapp" is the target CP-app in question and rewrite
SCRIPT_NAME from "/apps/cherrypy" to "/apps/cherrypy/projectapp" and
PATH_INFO to "/tags/filters", that is fine with me.

I actually do that in my WSGIAppFilter - I use
_cputil.get_object_trail() to determine what portion of PATH_INFO
corresponds to objects mounted on the tree.  So SCRIPT_NAME becomes
SCRIPT_NAME + cp_tree_object_parts.  The remainder of the path that
doesn't correspond to objects in the CP tree is set to PATH_INFO.  Thus,
the hosted wsgi app gets a SCRIPT_NAME and PATH_INFO that are correct in
its context.

> PEP 333 takes pains to say "the application object" or "the application
> callable" in many, many places where it could have just said "the
> application"--I think there's a reason, and it is that "the callable" is
> supposed to be decoupled from "the application". One common way to
> implement that for a framework is to make "the callable" a factory
> function which returns "the real callable"; I chose in CP to use
> polymorphism ("many apps -> one function") rather than use a factory
> ("many apps -> one function -> many functions").

I like the polymorphism approach.  I just think that the
_cpwsgi.wsgiApp, as a single "application callable", should dispatch to
its multiple hosted wsgi apps with PATH_INFO (i.e., that should be the
object_path).  From within, if it wants to rewrite SCRIPT_NAME and
PATH_INFO to reflect the true location of the internal app, that is
fine.   It really is the only way that a correct SCRIPT_NAME and
PATH_INFO could be set since only CP knows the internal object structure
of the tree.

So here is what I am proposing, in a nutshell:

1. Have CP ignore SCRIPT_NAME for locating the object requested.
2. Use PATH_INFO to locate the requested object.
3. Optionally: rewrite SCRIPT_NAME to be the original SCRIPT_NAME + the
"found application" (however that is determined - I gave my
WSGIAppFilter example).
4. Use SCRIPT_NAME + path when writing issuing redirects and other URL
writing tasks.

> /soapbox off ;)

Me too :-)

Christian


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Christian Wyglendowski  
View profile  
 More options Feb 5 2006, 11:22 am
From: Christian Wyglendowski <christ...@dowski.com>
Date: Sun, 05 Feb 2006 10:22:52 -0600
Local: Sun, Feb 5 2006 11:22 am
Subject: Re: [cherrypy-devel] Re: WSGI environ
Alright, I took a different approach on this.  As you suggested, I went
after _cpwsgiserver this time.

Robert Brewer wrote:
> Are we still talking about your patch for #455? I don't understand why
> _cpwsgi doesn't do what you want already. I most definitely can
> understand that _cpwsgiserver doesn't set SCRIPT_NAME and PATH_INFO per
> the spec. That should be changed to properly set those values.

I have updated #455 (http://www.cherrypy.org/ticket/455) with a new
patch.  _cpwsgiserver should now set the correct SCRIPT_NAME and
PATH_INFO.  It probably still needs some fine tuning, but I didn't want
to go much further on it until I got some feedback (yea or nay).

> That
> would mean making the WSGIServer more configurable; you'd have to tell
> it all of your app roots when you start it up (like every other WSGI
> server is being forced to do).

That is basically what I did.  The default behavior still simply takes a
single app and serves it.  There is now an add_application(path, app)
method that lets you mount an app at a different point.  As I think
about it, maybe this behavior should mirror the cherrypy.tree object a
little more.  Maybe server.add_application() should become server.mount()?

Anyhow, the bottom line is that _cpwsgiserver can now host multiple WSGI
apps at multiple locations.  The mount point for the application becomes
its SCRIPT_NAME.  When a URL is requested, the server determines by its
path which application should handle it.

> This would take a bit of work to get
> server.start to pass CP's tree.mount_points to the WSGI server, while
> still remaining decoupled.

Hhhmm...I wasn't really sure what you meant by this.  I'm not sure why
the _cpwsgiserver would need to be aware of application locations within
the main wsgiApp callable.

> In other words, SCRIPT_NAME and PATH_INFO
> should be fixed in _cpwsgiserver.HTTPRequest.parse_request, not in
> _cpwsgi.CPHTTPRequest.parse_request.

Thanks for bearing with me on this still.  Maybe even with this latest
patch this idea still isn't feasible, but I have at least got a better
understanding of the inner workings of CP in the process :-)  What I
have put together passed all current tests, but would of course require
new tests if it is a direction we want to go.

Here is an example of using the new setup:

import cherrypy
from cherrypy._cpwsgi import wsgiApp
from somepackage import somemiddleware, some_simple_app

class Root:
     @cherrypy.expose
     def index(self):
         return "Hello, world!"

wrapped_app = somemiddleware(wsgiApp)

cherrypy.tree.mount(Root(), '/')

# tell CP to use our custom wrapped CP wsgiApp
cherrypy.server.cp_wsgi_app = wrapped_app

# add another wsgi app to host (maybe this is beyond the scope of CP?)
cherrypy.server.mount_wsgi_app('/over/here', some_simple_app)

cherrypy.server.start()


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Christian Wyglendowski  
View profile  
 More options Feb 6 2006, 7:32 am
From: Christian Wyglendowski <christ...@dowski.com>
Date: Mon, 06 Feb 2006 06:32:18 -0600
Local: Mon, Feb 6 2006 7:32 am
Subject: Re: [cherrypy-devel] Re: WSGI environ

Christian Wyglendowski wrote:
> # add another wsgi app to host (maybe this is beyond the scope of CP?)
> cherrypy.server.mount_wsgi_app('/over/here', some_simple_app)

Ok, I'll answer my own question.  It *is* beyond the scope of CP.  I
have removed it in my latest patch attached to the ticket.

Christian
http://www.dowski.com


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages < Older 
« Back to Discussions « Newer topic     Older topic »