Web2 Script.py seems to be broken
from twisted.application import strports, service from twisted.web2 import static, server, http, script root = static.File("./adir") root.indexNames=['index.rpy'] root.processors = {'.rpy': script.ResourceScript} application = service.Application("web") site = server.Site(root) s = strports.service('tcp:8000', http.HTTPFactory(site)) s.setServiceParent(application) Get error, noRsrc = error.ErrorPage(500, "Whoops! Internal Error", rpyNoResource) exceptions.AttributeError: 'module' object has no attribute 'ErrorPage' Failed to load application: 'module' object has no attribute 'ErrorPage' Looking in api docs for web2.error I don't see an ErrorPage, but it does exist in web.error Todd Thomas
Indeed it is broken; in SVN twisted.web2.script currently starts with the line: raise ImportError("FIXME: this file probably doesn't work.") I think that fixes the particular problem you're seeing. ;) There's no reason it should be hard to support .rpy files in web2, but nobody has done anything about it. Part of the reason being that RPYs have somewhat fallen out of favor and are generally discouraged. However, I do see that they're sometimes useful as a solution sort of in between CGI and internal code, so I wouldn't mind seeing support return. It's not on my list of things I want to do soon, though. James
On 2/7/06, James Y Knight <foom@fuhm.net> wrote:
Indeed it is broken; in SVN twisted.web2.script currently starts with the line:
raise ImportError("FIXME: this file probably doesn't work.")
I think that fixes the particular problem you're seeing. ;)
There's no reason it should be hard to support .rpy files in web2, but nobody has done anything about it. Part of the reason being that RPYs have somewhat fallen out of favor and are generally discouraged. However, I do see that they're sometimes useful as a solution sort of in between CGI and internal code, so I wouldn't mind seeing support return. It's not on my list of things I want to do soon, though.
James
_______________________________________________ Twisted-web mailing list Twisted-web@twistedmatrix.com http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-web
I find them extemely handy personally, how else are you going add resources without resorting to restarting the server? But I guess depends on what you are using them for. I tend to use twisted more for testing and experimenting, simpler than installing apache. Unfortunately twisted-web doesnt have a wsgi implementation, I have been messing around with django a bit trying to see how modular the code is.
Todd Thomas wrote:
I find them extemely handy personally, how else are you going add resources without resorting to restarting the server? But I guess depends on what you are using them for. I tend to use twisted more for testing and experimenting, simpler than installing apache. Unfortunately twisted-web doesnt have a wsgi implementation, I have been messing around with django a bit trying to see how modular the code is.
If all you want is something easier to configure/install than apache I'd suggest lighttpd. Unless you've got a pre-existing twisted.web2 deployment and pre-existing twisted.web2 using code, I don't see a reason to use twisted which is very unstable, going to change radically, and probably doesn't work anyway. :) Of course if you really want to use twisted.web2.script you're welcome to submit patches to the bugtracker. -David
On 2/7/06, David Reid <dreid@dreid.org> wrote:
Todd Thomas wrote:
I find them extemely handy personally, how else are you going add resources without resorting to restarting the server? But I guess depends on what you are using them for. I tend to use twisted more for testing and experimenting, simpler than installing apache. Unfortunately twisted-web doesnt have a wsgi implementation, I have been messing around with django a bit trying to see how modular the code is.
If all you want is something easier to configure/install than apache I'd suggest lighttpd. Unless you've got a pre-existing twisted.web2 deployment and pre-existing twisted.web2 using code, I don't see a reason to use twisted which is very unstable, going to change radically, and probably doesn't work anyway. :)
Of course if you really want to use twisted.web2.script you're welcome to submit patches to the bugtracker.
-David
_______________________________________________ Twisted-web mailing list Twisted-web@twistedmatrix.com http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-web
Up to this point I have been using twisted-web exclusively. Would it be considered stable at this point, and is it still being worked on actively? Or is all the efforts now going towards stabilizing twisted-web2? -ToddB
On Feb 7, 2006, at 4:09 AM, Todd Thomas wrote:
I find them extemely handy personally, how else are you going add resources without resorting to restarting the server? But I guess depends on what you are using them for. I tend to use twisted more for testing and experimenting, simpler than installing apache. Unfortunately twisted-web doesnt have a wsgi implementation, I have been messing around with django a bit trying to see how modular the code is.
You'll notice that I said I was open to them still being supported. I'll take a submission of code + unit tests for it, or if not, will get around to implementing it someday. I'll also note, it should be possible to use twisted.web.script from within a twisted.web2 server, although you won't be able to use web2 Resources in the rpys loaded by the twisted.web.script loader. (The compatibility only works one way -- you can use old resources inside new ones, but not new ones inside old ones). I think you might have meant this but it wasn't entirely clear so I'll also note that twisted.web2 does support wsgi. James
On 2/7/06, James Y Knight <foom@fuhm.net> wrote:
On Feb 7, 2006, at 4:09 AM, Todd Thomas wrote:
I find them extemely handy personally, how else are you going add resources without resorting to restarting the server? But I guess depends on what you are using them for. I tend to use twisted more for testing and experimenting, simpler than installing apache. Unfortunately twisted-web doesnt have a wsgi implementation, I have been messing around with django a bit trying to see how modular the code is.
You'll notice that I said I was open to them still being supported. I'll take a submission of code + unit tests for it, or if not, will get around to implementing it someday.
I'll also note, it should be possible to use twisted.web.script from within a twisted.web2 server, although you won't be able to use web2 Resources in the rpys loaded by the twisted.web.script loader. (The compatibility only works one way -- you can use old resources inside new ones, but not new ones inside old ones).
I think you might have meant this but it wasn't entirely clear so I'll also note that twisted.web2 does support wsgi.
James
_______________________________________________ Twisted-web mailing list Twisted-web@twistedmatrix.com http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-web
It does support wsgi, I was playing around with it. I went back to twisted-web, I like its lower level approach. Using http.request directly vs. resources is nice since I can pretty much tell exactly what is going on. I love the fact that you can work at an extremely low level in twisted-web. I hope twisted-web2 doesn't get too high level. Resources are great when your making a standalone web app, but not so great when you are wanting to build frameworks on top of them. The biggest attraction for me in twisted is the fact that it pretty much allows you freedom to do anything. I am considering writing a wsgi handler for twisted-web. I think it would be a good project.
Todd Thomas wrote:
On 2/7/06, *James Y Knight* <foom@fuhm.net <mailto:foom@fuhm.net>> wrote:
On Feb 7, 2006, at 4:09 AM, Todd Thomas wrote: > I find them extemely handy personally, how else are you going add > resources without resorting to restarting the server? But I guess > depends on what you are using them for. I tend to use twisted more > for testing and experimenting, simpler than installing apache. > Unfortunately twisted-web doesnt have a wsgi implementation, I have > been messing around with django a bit trying to see how modular the > code is.
You'll notice that I said I was open to them still being supported. I'll take a submission of code + unit tests for it, or if not, will get around to implementing it someday.
I'll also note, it should be possible to use twisted.web.script from within a twisted.web2 server, although you won't be able to use web2 Resources in the rpys loaded by the twisted.web.script loader. (The compatibility only works one way -- you can use old resources inside new ones, but not new ones inside old ones).
I think you might have meant this but it wasn't entirely clear so I'll also note that twisted.web2 does support wsgi.
James
_______________________________________________ Twisted-web mailing list Twisted-web@twistedmatrix.com <mailto:Twisted-web@twistedmatrix.com> http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-web <http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-web>
It does support wsgi, I was playing around with it. I went back to twisted-web, I like its lower level approach. Using http.request directly vs. resources is nice since I can pretty much tell exactly what is going on. I love the fact that you can work at an extremely low level in twisted-web. I hope twisted-web2 doesn't get too high level.
WARNING: completely untested ideas ahead. I'm not a big web2 user (yet). I doubt it's difficult to write a server.Site equivalent to plug an alternative framework directly into web2's HTTP protocol support. IIRC, HTTPFactory expects nothing more than something callable that takes a bunch of args. Also, a root Resource that calls out to an alternative framework should be trivial to implement. See t.web2.iweb.IResource for details. You don't even need to subclass resource.Resource. Once your framework handling resource is called it should be able to do just about anything it wants as long as its renderHTTP returns an http.Response instance. - Matt -- __ / \__ Matt Goodall, Pollenation Internet Ltd \__/ \ w: http://www.pollenation.net __/ \__/ e: matt@pollenation.net / \__/ \ t: +44 (0)113 2252500 \__/ \__/ / \ Any views expressed are my own and do not necessarily \__/ reflect the views of my employer.
Matt Goodall wrote:
Todd Thomas wrote:
On 2/7/06, *James Y Knight* <foom@fuhm.net <mailto:foom@fuhm.net>> wrote:
On Feb 7, 2006, at 4:09 AM, Todd Thomas wrote:
I find them extemely handy personally, how else are you going add resources without resorting to restarting the server? But I guess depends on what you are using them for. I tend to use twisted more for testing and experimenting, simpler than installing apache. Unfortunately twisted-web doesnt have a wsgi implementation, I have been messing around with django a bit trying to see how modular the code is.
You'll notice that I said I was open to them still being supported. I'll take a submission of code + unit tests for it, or if not, will get around to implementing it someday.
I'll also note, it should be possible to use twisted.web.script from within a twisted.web2 server, although you won't be able to use web2 Resources in the rpys loaded by the twisted.web.script loader. (The compatibility only works one way -- you can use old resources inside new ones, but not new ones inside old ones).
I think you might have meant this but it wasn't entirely clear so I'll also note that twisted.web2 does support wsgi.
James
_______________________________________________ Twisted-web mailing list Twisted-web@twistedmatrix.com <mailto:Twisted-web@twistedmatrix.com> http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-web <http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-web>
It does support wsgi, I was playing around with it. I went back to twisted-web, I like its lower level approach. Using http.request directly vs. resources is nice since I can pretty much tell exactly what is going on. I love the fact that you can work at an extremely low level in twisted-web. I hope twisted-web2 doesn't get too high level.
I doubt it's difficult to write a server.Site equivalent to plug an alternative framework directly into web2's HTTP protocol support. IIRC, HTTPFactory expects nothing more than something callable that takes a bunch of args.
Please don't do this.
Also, a root Resource that calls out to an alternative framework should be trivial to implement. See t.web2.iweb.IResource for details. You don't even need to subclass resource.Resource.
Please do this. If you're going to write another web framework on top of twisted.web2 you should atleast be able to deploy it along side normal twisted.web2 resources or resources from another such framework. locateChild makes this very easy, because you can consume an arbitrary number of path segments at any point. (I know you know this Matt but you made the suggestion so you get the reply ;)) -David
Todd Thomas wrote:
It does support wsgi, I was playing around with it. I went back to twisted-web, I like its lower level approach. Using http.request directly vs. resources is nice since I can pretty much tell exactly what is going on. I love the fact that you can work at an extremely low level in twisted-web. I hope twisted-web2 doesn't get too high level.
I don't really understand this, twisted.web _has_ resources. They're not very good in that one resource is expected to return another resource to consume the next segment in the path, which makes it hard to stop the machinery. But if you mean what I think you mean (which I hope you don't) and that you're working with your own server.Site then I'd say you need twisted.web2 more than anyone, because it's resource api will allow you to make your framework work along side others. Which is one of the problems with current Nevow and part of the reason twisted.web2 was started. -David
On 2/8/06, David Reid <dreid@dreid.org> wrote:
Todd Thomas wrote:
It does support wsgi, I was playing around with it. I went back to twisted-web, I like its lower level approach. Using http.request directly vs. resources is nice since I can pretty much tell exactly what is going on. I love the fact that you can work at an extremely low level in twisted-web. I hope twisted-web2 doesn't get too high level.
I don't really understand this, twisted.web _has_ resources. They're not very good in that one resource is expected to return another resource to consume the next segment in the path, which makes it hard to stop the machinery. But if you mean what I think you mean (which I hope you don't) and that you're working with your own server.Site then I'd say you need twisted.web2 more than anyone, because it's resource api will allow you to make your framework work along side others. Which is one of the problems with current Nevow and part of the reason twisted.web2 was started.
-David
_______________________________________________ Twisted-web mailing list Twisted-web@twistedmatrix.com http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-web
You just described exactly the problem I am currently having with twisted-web2. I tried to create wsgi as a root resource, however its also dependent on static files in media directory. I wasn't able to create a child object due to no matter what it passes full path to the wsgi application. So then I made it a child of a root resource, this sort of worked. But since the root path was consumed when it is passed to the child resource, when the application does a redirect, it creates the url in relation to root, not the child url. In my own application I could work around this without too much difficulty since I already know where my child is in relation to the root object.
On 2/8/06, Todd Thomas <caliban19@gmail.com> wrote:
On 2/8/06, David Reid <dreid@dreid.org> wrote:
Todd Thomas wrote:
It does support wsgi, I was playing around with it. I went back to twisted-web, I like its lower level approach. Using http.request directly vs. resources is nice since I can pretty much tell exactly what is going on. I love the fact that you can work at an extremely low level in twisted-web. I hope twisted-web2 doesn't get too high level.
I don't really understand this, twisted.web _has_ resources. They're not very good in that one resource is expected to return another resource to consume the next segment in the path, which makes it hard to stop the machinery. But if you mean what I think you mean (which I hope you don't) and that you're working with your own server.Site then I'd say you need twisted.web2 more than anyone, because it's resource api will allow you to make your framework work along side others. Which is one of the problems with current Nevow and part of the reason twisted.web2 was started.
-David
_______________________________________________ Twisted-web mailing list Twisted-web@twistedmatrix.com http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-web
You just described exactly the problem I am currently having with twisted-web2. I tried to create wsgi as a root resource, however its also dependent on static files in media directory. I wasn't able to create a child object due to no matter what it passes full path to the wsgi application. So then I made it a child of a root resource, this sort of worked. But since the root path was consumed when it is passed to the child resource, when the application does a redirect, it creates the url in relation to root, not the child url. In my own application I could work around this without too much difficulty since I already know where my child is in relation to the root object.
Okay, I seemed to have solved most of my problems. Only issue having now is pysqlite2 doesn't like being called from threads seperate from the ones that created it. It could be run as a deferred in this case since it does respond pretty quick. But I am sure could solve this issue simply by changing to mysql or postgresql. The solution was stupidly simple. from twisted.application import strports, service from twisted.web2 import static, server, http, wsgi, resource import sys sys.path.append("./myproject") from django.core.handlers.wsgi import WSGIHandler import os os.environ['DJANGO_SETTINGS_MODULE'] = 'myproject.settings' class toplevel(wsgi.WSGIResource): def child_media(self, ctx): return static.File("./myproject/media") root = toplevel(WSGIHandler()) application = service.Application("web") site = server.Site(root) s = strports.service('tcp:8000', http.HTTPFactory(site)) s.setServiceParent(application) It works fairly well, or would if I wasn't testing on windows. Before you ask why windows. I have box I dual boot into and normally run secure shell to, using ubuntu linux currently. Unfortunately my computer has sims 2 on which my g/f has been playing religiously lately. So I am stuck using windows at work for right now. ToddB
On 2/9/06, Todd Thomas <caliban19@gmail.com> wrote:
On 2/8/06, Todd Thomas <caliban19@gmail.com> wrote:
On 2/8/06, David Reid < dreid@dreid.org> wrote:
Todd Thomas wrote:
It does support wsgi, I was playing around with it. I went back to twisted-web, I like its lower level approach. Using http.request directly vs. resources is nice since I can pretty much tell exactly what is going on. I love the fact that you can work at an extremely low level in twisted-web. I hope twisted-web2 doesn't get too high level.
I don't really understand this, twisted.web _has_ resources. They're not very good in that one resource is expected to return another resource to consume the next segment in the path, which makes it hard to stop the machinery. But if you mean what I think you mean (which I hope you don't) and that you're working with your own server.Site then I'd say you need twisted.web2 more than anyone, because it's resource api will allow you to make your framework work along side others. Which is one of the problems with current Nevow and part of the reason twisted.web2 was started.
-David
_______________________________________________ Twisted-web mailing list Twisted-web@twistedmatrix.com http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-web
You just described exactly the problem I am currently having with twisted-web2. I tried to create wsgi as a root resource, however its also dependent on static files in media directory. I wasn't able to create a child object due to no matter what it passes full path to the wsgi application. So then I made it a child of a root resource, this sort of worked. But since the root path was consumed when it is passed to the child resource, when the application does a redirect, it creates the url in relation to root, not the child url. In my own application I could work around this without too much difficulty since I already know where my child is in relation to the root object.
Okay, I seemed to have solved most of my problems. Only issue having now is pysqlite2 doesn't like being called from threads seperate from the ones that created it. It could be run as a deferred in this case since it does respond pretty quick. But I am sure could solve this issue simply by changing to mysql or postgresql. The solution was stupidly simple.
from twisted.application import strports, service from twisted.web2 import static, server, http, wsgi, resource
import sys sys.path.append("./myproject") from django.core.handlers.wsgi import WSGIHandler import os os.environ['DJANGO_SETTINGS_MODULE'] = 'myproject.settings'
class toplevel(wsgi.WSGIResource):
def child_media(self, ctx): return static.File("./myproject/media")
root = toplevel(WSGIHandler()) application = service.Application("web") site = server.Site(root) s = strports.service('tcp:8000', http.HTTPFactory(site)) s.setServiceParent(application)
It works fairly well, or would if I wasn't testing on windows. Before you ask why windows. I have box I dual boot into and normally run secure shell to, using ubuntu linux currently. Unfortunately my computer has sims 2 on which my g/f has been playing religiously lately. So I am stuck using windows at work for right now.
ToddB
I was wrong, the css and js were cached, media directory is unreachable using this code. Which I thought it would be since wsgi.WSGIResourceimplements its own locate child. Any ideas of something that could work?
from twisted.application import strports, service from twisted.web2 import static, server, http, wsgi, resource
import sys sys.path.append("./myproject") from django.core.handlers.wsgi import WSGIHandler import os os.environ['DJANGO_SETTINGS_MODULE'] = 'myproject.settings'
class toplevel(wsgi.WSGIResource):
def child_media(self, ctx): return static.File("./myproject/media")
root = toplevel(WSGIHandler()) application = service.Application("web") site = server.Site(root) s = strports.service('tcp:8000', http.HTTPFactory(site)) s.setServiceParent(application)
That won't work -- what you want is to nest the resources rather than subclass them. Something like this resource should do you (untested, wrote in email client). It says: if the path starts with media, return the static File and pass it the remaining pieces of the path, otherwise pass the entire path onto wsgi for its processing. class toplevel(object): implements(IResource) def __init__(self): self.wsgi = wsgi.WSGIResource(WSGIHandler()) self.media = static.File("./myproject/media" def locateChild(self, req, segs): if segs[0] == 'media': return self.media, segs[1:] return self.wsgi, segs def renderHTTP(self, req): return self.wsgi James
On 2/9/06, James Y Knight <foom@fuhm.net> wrote:
from twisted.application import strports, service from twisted.web2 import static, server, http, wsgi, resource
import sys sys.path.append("./myproject") from django.core.handlers.wsgi import WSGIHandler import os os.environ['DJANGO_SETTINGS_MODULE'] = 'myproject.settings'
class toplevel(wsgi.WSGIResource):
def child_media(self, ctx): return static.File("./myproject/media")
root = toplevel(WSGIHandler()) application = service.Application("web") site = server.Site(root) s = strports.service('tcp:8000', http.HTTPFactory(site)) s.setServiceParent(application)
That won't work -- what you want is to nest the resources rather than subclass them. Something like this resource should do you (untested, wrote in email client). It says: if the path starts with media, return the static File and pass it the remaining pieces of the path, otherwise pass the entire path onto wsgi for its processing.
class toplevel(object): implements(IResource)
def __init__(self): self.wsgi = wsgi.WSGIResource(WSGIHandler()) self.media = static.File("./myproject/media"
def locateChild(self, req, segs): if segs[0] == 'media': return self.media, segs[1:] return self.wsgi, segs
def renderHTTP(self, req): return self.wsgi
James
_______________________________________________ Twisted-web mailing list Twisted-web@twistedmatrix.com http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-web
The final solution I came up with is.. from twisted.application import strports, service from twisted.web2 import static, server, http, wsgi, resource import sys sys.path.append("./myproject") from django.core.handlers.wsgi import WSGIHandler import os os.environ['DJANGO_SETTINGS_MODULE'] = 'myproject.settings' wsgi = wsgi.WSGIResource(WSGIHandler()) root = wsgi application = service.Application("web") site = server.Site(root) s = strports.service('tcp:8000', http.HTTPFactory(site)) s.setServiceParent(application) media = static.File("./myproject/media") site2 = server.Site(media) m = strports.service('tcp:8080', http.HTTPFactory(site2)) m.setServiceParent(application) But what you show is awesome, been looking at how to do something like that. Thanks for all the help, this issue is officially solved.. ToddB
participants (4)
-
David Reid
-
James Y Knight
-
Matt Goodall
-
Todd Thomas