[Twisted-Python] confusion with general web serving
i'm missing a key piece of connectivity here: i'm building a twisted daemon to serve files. right now it will serve off a local structure, in the future it will do that + handle proxying to s3. I stripped out all the app specific code below. my issue is that i can't figure out how to display a file on the system for a url, short of slurping it i thought static.File would have soemthing to do with it, but I can't figure out how to get it into the http.Request.process routine. suggestions ? ---------------------------------------------------- class UserphotoRequestHandler(http.Request): re_userphoto= re.compile("""^\w{32}(?:_[smlt])?.jpg$""") def process(self): if self.path == '/favicon.ico': self.finish() return if not self.re_userphoto.findall( self.path ): return return_notFound() myFilname= self.db_lookup(): if not myFilname: return return_notFound() # how do i render myFilename ? self.finish() def return_notFound( self ): self.setResponseCode(http.NOT_FOUND) self.write("invalid request.") self.finish() 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 wrote:
i'm missing a key piece of connectivity here:
i'm building a twisted daemon to serve files. right now it will serve off a local structure, in the future it will do that + handle proxying to s3.
I stripped out all the app specific code below. my issue is that i can't figure out how to display a file on the system for a url, short of slurping it
i thought static.File would have soemthing to do with it, but I can't figure out how to get it into the http.Request.process routine.
You're asking on the wrong list really - you should ask on twisted-web Your problem is that you're trying to implement the HTTP protocol. Don't do that, it's not needed. You need to hook the protocol up to a "site" into which you can put components. This is well documented. See: http://twistedmatrix.com/projects/web/documentation/howto/using-twistedweb.h...
On Apr 15, 2007, at 7:45 AM, Phil Mayers wrote:
Jonathan Vanasco wrote:
i'm missing a key piece of connectivity here: i'm building a twisted daemon to serve files. right now it will serve off a local structure, in the future it will do that + handle proxying to s3. I stripped out all the app specific code below. my issue is that i can't figure out how to display a file on the system for a url, short of slurping it i thought static.File would have soemthing to do with it, but I can't figure out how to get it into the http.Request.process routine.
You're asking on the wrong list really - you should ask on twisted-web
Your problem is that you're trying to implement the HTTP protocol. Don't do that, it's not needed. You need to hook the protocol up to a "site" into which you can put components.
This is well documented. See:
http://twistedmatrix.com/projects/web/documentation/howto/using- twistedweb.html#auto2
Thanks, I''ll check out the other list. I hadn't read that howto -- just the oreilley book and the overall design of the daemn seemed more inline with using the protocol ( as I'll mixing up proxy , static, and dynamic files ) than the web examples in the book. // 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 -
Phil Mayers