[Twisted-web] Simple Threaded Web Server on Twisted

Alex Murphy murphy at sgtp.samara.ru
Thu Jun 3 22:14:47 MDT 2004

 The small web-server was necessary for the development written on
python for me. I write it on a basis twisted. All is simply excellent -
twisted rules. That only there is a variable args with all in parameters
transferred of inquiry. But here there was a question how to make
sessions?? Yes I understand, what on basis Cookie all turns out without
ceremony, but I saw object session, only I can not understand as them to
use? I bring below my code, at the same time tell where I have admitted

mtp is mine handler which processes files with expansion mpt. If it is
possible, correct wrong places of a code and result an example of use
cookie sessions.

 Yours faithfully, Alexey.
#!/bin/env python
root_dir = 'wwwroot'
version = '0.1'

# Import need twisted module
from twisted.web import static, server, vhost, twcgi, script
from twisted.internet import reactor, protocol

# MPT Handle
def handle_mpt(x,fn,env,qargs):
    request = x.request

  # me handlers

server.version = "MPT_Server %s" % version
class MPTScript(twcgi.CGIScript):
    def runProcess(self, env, request, qargs=[]):
        p = twcgi.CGIProcessProtocol(request)
root = static.File(root_dir)
root.processors = {
            '.mpt': MPTScript,
            '.cgi': twcgi.CGIScript,
            '.php3': twcgi.PHP3Script,
            '.php': twcgi.PHPScript,
root.putChild('vhost', vhost.VHostMonsterResource())
site = server.Site(root)
reactor.listenTCP(8080, site)

More information about the Twisted-web mailing list