def runscgi(func, addr=("localhost", 4000)): """Runs a WSGI function as an SCGI server.""" import flup.server.scgi as flups return flups.WSGIServer(func, bindAddress=addr, debug=False).run()
def runfcgi(func, addr=("localhost", 8000)): """Runs a WSGI function as a FastCGI server.""" import flup.server.fcgi as flups return flups.WSGIServer(func, multiplexed=True, bindAddress=addr, debug=False).run()
def run_flup(app, *args, **kwargs): from flup.server import fcgi fcgi.WSGIServer(app).run()
str += ", rquest_uri:" + rquest_uri + "\r\n" remote_addr = environ["REMOTE_ADDR"] str += ",remote_addr:" + remote_addr + "\r\n" remote_port = environ["REMOTE_PORT"] str += ",remote_port:" + remote_port + "\r\n" data = environ["wsgi.input"].read() str += ", data:" + data + "\r\n" return str def application(environ, start_response): #logging.basicConfig(level=logging.DEBUG, # format='%(asctime)s %(filename)s[line:%(lineno)d] %(levelname)s %(message)s', # datefmt='%a, %d %b %Y %H:%M:%S', # filename='/tmp/test.log', # filemode='w') start_response('200 OK', [('Content-Type', 'text/plain')]) (ret, params) = get_params(environ) #logging.debug("application------------", params) if not ret: return ["failed"] (ret, status) = upload_qiniu(params) #content = get_environ(environ) return [status] if __name__ == "__main__": set_default(connection_pool=30) #flups.WSGIServer(application, multithreaded=True, multiprocess=False, bindAddress=('127.0.0.1, 21000')).run() flups.WSGIServer(application).run()
sys.stdout = result a.setup_args(environ['wsgi.input'],None,"",environ) a.execute_query() result.seek(0) header=result.read(10) while header: header=header+result.read(10) hsplit=re.split(r'\r?\n\r?\n',header) if len(hsplit) == 2: htree=re.split(r'\r?\n',hsplit[0]) headers=[tuple(x.split(": ",1)) for x in htree] start_response('200 OK', headers) header=None line=hsplit[1] if line == "": line=result.read(10) while line: yield(line) line=result.read(10) result.close() sys.stdout=old_stdout #Faking HTTP_HOST environment for silkapi to think of this as HTTP Request a=silkapi.SilkAPI() #Fast CGI server can listen on port 4040 #In apache load module libapache2-mod-fastcgi and add the following line ##FastCgiServer /var/www/download/fcgi-test.py -processes 4 -port 4040 fcgi.WSGIServer(app, bindAddress = ('127.0.0.1',4040)).run()
def runfcgi(func, socket_path='%(socket_path)s'): import flup.server.fcgi as flups return flups.WSGIServer(func, multiplexed=True, bindAddress=socket_path).run()