[Twisted-web] Using web2 to run a Cherrpy site
Joshua Boverhof
JRBoverhof at lbl.gov
Thu Mar 22 14:18:23 CST 2007
Here is a fix.
It looks like a bug in twisted.web2.twcgi to me. Cherrypy is
confused by the "//".
-josh
> svn diff
Index: twcgi.py
===================================================================
--- twcgi.py (revision 19890)
+++ twcgi.py (working copy)
@@ -51,7 +51,7 @@
if request.postpath:
# Should we raise an exception if this contains "/" chars?
- env["PATH_INFO"] = '/' + '/'.join(request.postpath)
+ env["PATH_INFO"] = '/'.join(request.postpath)
# MUST always be present, even if no query
env["QUERY_STRING"] = request.querystring
On Mar 20, 2007, at 8:55 AM, David Konerding wrote:
>
>
>
> Which version of cherrypy are you using? I did an easy_install
> cherrypy and got 3.0.1 but your code didn't work on it. wsgiApp is
> somewhere else now or something.
>
>
> OK, I've updated my test example to work with CherryPy 3.0. This
> works a bit better,
> in fact, when I visit the root of the site I get my cherrypy
> application! Since
> I'm not tied to CherryPy 2.2 (unless TurboGears requires it) this
> 'fixes' most of my problem.
> I'm still having a problem if I access some URLs under the root,
> but I have yet to determine if it's going
> to be a problem.
>
> Here's a CherryPy 3.0.1 application that works with Twisted web2
> using the WSGI app support.
>
> from twisted.internet import reactor
> from twisted.application import service, strports
> from twisted.web2 import server, channel
> from twisted.web2 import log
> from twisted.web2 import wsgi
> from twisted.web2.wsgi import WSGIResource
> import cherrypy
>
> ## Basic cherrypy index object that dumps the WSGI environment
> class Root(object):
> @cherrypy.expose
> def index(self):
> s = []
> for key in cherrypy.request.wsgi_environ:
> s.append("%s=%s<br/>" % (key,
> cherrypy.request.wsgi_environ [key]))
>
> return "".join(s)
>
> ## Create an instance of the root application and mount it at /
> r = Root()
>
> ## Convert the Root application to a hostable WSGI application
> cpwsgiapp = cherrypy.Application(Root(), '/')
>
> ## Convert the CherryPy WSGI app to a Twisted WSGI resource
> wsgi = wsgi.WSGIResource(cpwsgiapp)
>
> ## Set up the cherrypy environment
> cherrypy.config.update({
> 'server.environment':'production',
> })
>
> ## Start the cherrypy engine without starting a blocking server
> cherrypy.engine.start(blocking=False)
>
> ## Setup default common access logging
> res = log.LogWrapperResource(wsgi)
> log.DefaultCommonAccessLoggingObserver().start()
>
> # Create twisted web2 site
> site = server.Site(res)
>
> ## Launch the HTTP site at port 8080
>
> ## code path invoked by twistd
> if __name__ == '__builtin__':
> application = service.Application("demo")
> s = strports.service('tcp:8080', channel.HTTPFactory(site))
> s.setServiceParent(application)
>
> ## code path when run directly
> if __name__ == '__main__':
> from twisted.python import log as pythonlog
> import sys
> pythonlog.startLogging(sys.stdout)
> reactor.listenTCP(8080, channel.HTTPFactory (site))
> reactor.run()
>
>
>
> _______________________________________________
> Twisted-web mailing list
> Twisted-web at twistedmatrix.com
> http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-web
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 2526 bytes
Desc: not available
Url : http://twistedmatrix.com/pipermail/twisted-web/attachments/20070322/3a328245/smime.bin
More information about the Twisted-web
mailing list