Re: twisted

Steven Armstrong <[email protected]>
Newsgroups gmane.comp.web.pyblosxom.devel
Message-ID <[email protected]>
On 03/29/05 19:10, Blake Winton wrote:
> Steven Armstrong wrote:
>> CGI        >> /pyblosxom/web/pyblosxom.cgi
>> WSGI_CGI   >> /pyblosxom/web/pyblosxom_wsgi.cgi
>> twisted    >> /pyblosxom/web/pyblosxom.tac
>> mod_python >> /pyblosxom/web/wsgi_app.py
> 
> I'm a little confused as to how this last one is set up.  I can see that 
> the WSGI_CGI uses the application from wsgi_app, but I sort of expected 
> some code like:
>          from wsgiref.handlers import ModPythonHandler
>          from wsgi_app import application
> 
>          ModPythonHandler().run(application)
> in the mod_python case...
> 

The mod_python WSGI wrapper is not part of the wsgiref library. I wrote
it based on a example from the web-sig mailing list. You can find it at [1].

[1] http://www.c-area.ch/code/mp_wsgi_handler.py

> (Keeping in mind that most of my confusion stems from my inexperience in 
> this area, and not because your code is necessarily confusing.)
> 
> And while I'm here asking dumb questions, is it possible to run the 
> twisted service along with other services on the same port?  Does it 
> integrate nicely with other twisted services trying to run on port 8080, 
> or do we need a new port for every twisted service?
> 

I guess you should be able to run it same as any other twisted resource.
e.g. something like:

from twisted_wsgi import WSGIResource
from wsgi_app import application as pyblosxom_application

application = service.Application("xyz")
page = SomePage()
resource = WSGIResource(pyblosxom_application, async=False)
page.putChild('pyblosxom', resource)
s = internet.TCPServer(8080, server.Site(page))
s.setServiceParent(application)

Which should give you a Pyblosxom blog at localhost:8080/pyblosxom.
I can't remember the exact syntax for twisted, but it should look
something like the above example.

>> Where WSGI_CGI, twisted and mod_python all run the same program, namely
>> wsgi_app.py. They all use server dependant wrappers/connectors to setup
>> a WSGI compliant environment. Read the source for further infos and
>> dependencies.
> 
> Okay, so, are we agreed that we can remove the pyblosxom.cgi, as it 
> should be logically equivalent to pyblosxom_wsgi.cgi?  (And browsing 
> through the source, they look _extremely_ similar, which worries me as a 
> coder.  Twice the chance to make mistakes.)
> 

The problem here is that pyblosxom_wsgi.cgi depends on the wsgiref
library. I don't think users who only care about CGI should be forced to
install that.

The reason why pyblosxom_wsgi.cgi looks mostly like pyblosxom.cgi is
static rendering. The wsgi_app.py doesn't know anything about that, so
it has to be done in the cgi. I agree that it would be nicer to refactor
the code which is identical to some other place where both scripts have
access to it.
On the other hand, pyblosxom_wsgi.cgi was ment to be another testcase
for the wsgi-related code, not a replacement for pyblosxom.cgi.

>>>It looks like WSGI is a way to write our app, and have it 
>>>"automatically" connect to Twisted or mod_python or CGI, or what have 
>>>you.  If that's really the way it works, it would make our lives (by 
>>>which I mean Steven's life) a lot easier, since we could just write the 
>>>app once, and have the connectors deal with the various backends.
>> As noted above that's exactly how its implemented :-)
> 
> In the words of Will, "w00t!"  ;)
> 
> For a future direction, would it be useful to make the 
> Pyblosxom.pyblosxom.PyBlosxom class be more like an application, so that 
> we could get rid of the wsgi_app.py class entirely?  I think that might 
> be a slightly cleaner design, just from my 50,000' point of view.
> 

I totaly agree on this. I think it would generally be good to move from
the "collection of scripts" design to a more "application" design.

cheers
Steven




-------------------------------------------------------
SF email is sponsored by - The IT Product Guide
Read honest & candid reviews on hundreds of IT Products from real users.
Discover which products truly live up to the hype. Start reading now.
http://ads.osdn.com/?ad_id=6595&alloc_id=14396&op=click
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.