#!/usr/bin/python2.2
# Make sure the above line is correct for your system.
# Copyright (c) 2002 Samuel Brauer. All Rights Reserved. NO WARRANTY.
# $Revision: 1.1 $
import spb.makiEngine
import spb.fastcgiHttpTransaction
import os
import fcgi
THREADS = 1
try: import thread
except: THREADS = 0
if(THREADS): import threading
def handle_request(req):
try:
maki_trans = spb.fastcgiHttpTransaction.fastcgiHttpTransaction(req)
realpath = maki_trans.getRealPath()
realpath = spb.makiEngine.normalizeFilepath(realpath)
if(os.path.exists(realpath)):
spb.makiEngine.handleTransaction(maki_trans)
else:
maki_trans.sendError(404, "Not found", maki_trans.getEnvironValue("PATH_INFO"))
finally:
req.Finish()
if(THREADS):
class FastCGIThread(threading.Thread):
def __init__(self, req):
self._req = req
threading.Thread.__init__(self)
def run(self):
handle_request(self._req)
while fcgi.isFCGI():
req = fcgi.FCGI()
if(THREADS):
t = FastCGIThread(req)
t.start()
else:
handle_request(req)
|