confusion with general web serving
I asked this on the -python list, some suggested I re-ask here. I'm trying to build a small daemon that does the following: 1_ parse the uri for the key to an image 2_ validate that key against db 3_ if not valid, render a 404 4_ if valid, map to an arbitrary file on the fs ( pulled from db ) 4b_ or check a bdb to see if its on the fs, pull a copy off of amazon's s3 otherwise and update the cachedb to note we have it The issue that I'm having: i originally tried doing this based on one of the chapters in the twisted o'reilley book. i ran into issues when I tried to render an image -- i couldn't figure out how to do that. somone on twisted web suggested i not use the protocol and instead use site (http://twistedmatrix.com/projects/web/documentation/howto/ using-twistedweb.html#auto2 ). i ran into issues when trying to render status codes and add in proxy functionality. I'm at a loss on what I should be using. can someone offer advice ? == oreilley style == class UserphotoRequestHandler(http.Request): def process(self): pass class UserphotoHttp(http.HTTPChannel): requestFactory = UserphotoRequestHandler class UserphotoHttpFactory(http.HTTPFactory): protocol= UserphotoHttp if __name__ == "__main__": from twisted.internet import reactor reactor.listenTCP(7087, UserphotoHttpFactory()) reactor.run( ) // Jonathan Vanasco | - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | FindMeOn.com - The cure for Multiple Web Personality Disorder | Web Identity Management and 3D Social Networking | - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | RoadSound.com - Tools For Bands, Stuff For Fans | Collaborative Online Management And Syndication Tools | - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
On Tue, 17 Apr 2007 09:57:24 -0500, Jonathan Vanasco
I asked this on the -python list, some suggested I re-ask here.
I'm trying to build a small daemon that does the following:
1_ parse the uri for the key to an image 2_ validate that key against db 3_ if not valid, render a 404 4_ if valid, map to an arbitrary file on the fs ( pulled from db ) 4b_ or check a bdb to see if its on the fs, pull a copy off of amazon's s3 otherwise and update the cachedb to note we have it
The issue that I'm having:
i originally tried doing this based on one of the chapters in the twisted o'reilley book. i ran into issues when I tried to render an image -- i couldn't figure out how to do that.
somone on twisted web suggested i not use the protocol and instead use site (http://twistedmatrix.com/projects/web/documentation/howto/ using-twistedweb.html#auto2 ). i ran into issues when trying to render status codes and add in proxy functionality.
I'm at a loss on what I should be using. can someone offer advice ?
You are attacking this at too low a level, I think. In essence you are building a fixed-function web server, which is a waste of your time and resources, because twisted already has a decent web server implementation. Just make a .tac file for starters, something along these lines: --------------webserver.tac------------------------------------- # UNTESTED CODE I PULLED OUT OF MY EAR! from twisted.application import internet, service from twisted.python import log from twisted.web2 import channel, http from twisted.web2 import resource, responsecode, server class Image(resource.LeafResource): def __init__(self, key): self.key = key def render(self, request) # Locate the image, return some kind # of http.Response, or a defer.Deferred class Root(resource.Resource): addSlash = True def childFactory(self, request, name): return Image(name) def render(self, request): return http.Response( code=responsecode.OK, headers={}, stream='Blah' ) root = Root() site = server.Site(root) port = 8080 application = service.Application('ImageServer') svc = internet.TCPServer(port, channel.HTTPFactory(site)) svc.setServiceParent(application) --------------------------------------------------------------- Run the above with twistd -noy webserver.tac. This should be sufficient to get you started. Hope this helps, L. Daniel Burr
On Apr 17, 2007, at 11:20 AM, L. Daniel Burr wrote:
You are attacking this at too low a level, I think. In essence you are building a fixed-function web server, which is a waste of your time and resources, because twisted already has a decent web server implementation.
Just make a .tac file for starters, something along these lines:
Run the above with twistd -noy webserver.tac. This should be sufficient to get you started.
Thanks. Thats a big help -- it shows the interplay of more than just 2 classes, and gives me a good feel for Twisted web. I havne't touched twisted web in years , just other twisted portions. that puts a lot in perspective. // Jonathan Vanasco | - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | SyndiClick.com | - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | FindMeOn.com - The cure for Multiple Web Personality Disorder | Web Identity Management and 3D Social Networking | - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | RoadSound.com - Tools For Bands, Stuff For Fans | Collaborative Online Management And Syndication Tools | - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
participants (2)
-
Jonathan Vanasco
-
L. Daniel Burr