[Twisted-web] Default processing of a page in http.Request.process()

Steve doh tfif at hotmail.com
Sun Mar 4 19:27:25 CST 2007


Hi,
In the code below I am validating page requests and then want to cause a 
simple send of the known page to the browser. What class and method should I 
use?

Thanks Steve
----------------------------------------------------------------------------
import os, sys
from twisted.web import http, static, server, resource
from twisted.internet.protocol import Factory
from twisted.internet import reactor

class RequestHandler(http.Request):
    pageHandlers = {
        'index.html': 'def',
        'main.html': 'def',
        #'/posthandler': handlePost,
    }
    def process(self):
        filename = os.path.basename(self.path)
        print "[process] request = " + self.path

        if self.pageHandlers.has_key(filename):
            handler = self.pageHandlers[filename]
            if handler == 'def':
                ### What do I call here to simply get the page sent to the 
browser??? ####
            else:
                handler(self, filename)
        else:
            self.setHeader('Content-Type', 'text/html')
            self.setResponseCode(http.NOT_FOUND)
            self.write("<h1>Not Found</h1>Sorry, no such page.")
            self.finish()

class ServerProtocol(http.HTTPChannel):
    requestFactory = RequestHandler

os.chdir('D:\\html')

factory = http.HTTPFactory()
factory.protocol = ServerProtocol
reactor.listenTCP(80, factory)
reactor.run()

_________________________________________________________________
Find the coolest online games @ http://xtramsn.co.nz/gaming




More information about the Twisted-web mailing list