NovaBryan/EVE_Dump
Log | Files | 📦 下载最新源码 (.zip) | Refs | README

modfcgid.py (2546B)


      1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\carbon\common\lib\cherrypy\test\modfcgid.py
      2 import os
      3 curdir = os.path.join(os.getcwd(), os.path.dirname(__file__))
      4 import re
      5 import sys
      6 import time
      7 import cherrypy
      8 from cherrypy._cpcompat import ntob
      9 from cherrypy.process import plugins, servers
     10 from cherrypy.test import helper
     11 
     12 def read_process(cmd, args = ''):
     13     pipein, pipeout = os.popen4('%s %s' % (cmd, args))
     14     try:
     15         firstline = pipeout.readline()
     16         if re.search('(not recognized|No such file|not found)', firstline, re.IGNORECASE):
     17             raise IOError('%s must be on your system path.' % cmd)
     18         output = firstline + pipeout.read()
     19     finally:
     20         pipeout.close()
     21 
     22     return output
     23 
     24 
     25 APACHE_PATH = 'httpd'
     26 CONF_PATH = 'fcgi.conf'
     27 conf_fcgid = '\n# Apache2 server conf file for testing CherryPy with mod_fcgid.\n\nDocumentRoot "%(root)s"\nServerName 127.0.0.1\nListen %(port)s\nLoadModule fastcgi_module modules/mod_fastcgi.dll\nLoadModule rewrite_module modules/mod_rewrite.so\n\nOptions ExecCGI\nSetHandler fastcgi-script\nRewriteEngine On\nRewriteRule ^(.*)$ /fastcgi.pyc [L]\nFastCgiExternalServer "%(server)s" -host 127.0.0.1:4000\n'
     28 
     29 class ModFCGISupervisor(helper.LocalSupervisor):
     30     using_apache = True
     31     using_wsgi = True
     32     template = conf_fcgid
     33 
     34     def __str__(self):
     35         return 'FCGI Server on %s:%s' % (self.host, self.port)
     36 
     37     def start(self, modulename):
     38         cherrypy.server.httpserver = servers.FlupFCGIServer(application=cherrypy.tree, bindAddress=('127.0.0.1', 4000))
     39         cherrypy.server.httpserver.bind_addr = ('127.0.0.1', 4000)
     40         self.start_apache()
     41         helper.LocalServer.start(self, modulename)
     42 
     43     def start_apache(self):
     44         fcgiconf = CONF_PATH
     45         if not os.path.isabs(fcgiconf):
     46             fcgiconf = os.path.join(curdir, fcgiconf)
     47         f = open(fcgiconf, 'wb')
     48         try:
     49             server = repr(os.path.join(curdir, 'fastcgi.pyc'))[1:-1]
     50             output = self.template % {'port': self.port,
     51              'root': curdir,
     52              'server': server}
     53             output = ntob(output.replace('\r\n', '\n'))
     54             f.write(output)
     55         finally:
     56             f.close()
     57 
     58         result = read_process(APACHE_PATH, '-k start -f %s' % fcgiconf)
     59         if result:
     60             print result
     61 
     62     def stop(self):
     63         read_process(APACHE_PATH, '-k stop')
     64         helper.LocalServer.stop(self)
     65 
     66     def sync_apps(self):
     67         cherrypy.server.httpserver.fcgiserver.application = self.get_app()