[Twisted-Python] confusion with general web serving

Jonathan Vanasco twisted-python at 2xlp.com
Fri Apr 13 12:42:54 MDT 2007


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( )




More information about the Twisted-Python mailing list