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

modwsgi.py (3017B)


      1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\carbon\common\lib\cherrypy\test\modwsgi.py
      2 import os
      3 curdir = os.path.abspath(os.path.dirname(__file__))
      4 import re
      5 import sys
      6 import time
      7 import cherrypy
      8 from cherrypy.test import helper, webtest
      9 
     10 def read_process(cmd, args = ''):
     11     pipein, pipeout = os.popen4('%s %s' % (cmd, args))
     12     try:
     13         firstline = pipeout.readline()
     14         if re.search('(not recognized|No such file|not found)', firstline, re.IGNORECASE):
     15             raise IOError('%s must be on your system path.' % cmd)
     16         output = firstline + pipeout.read()
     17     finally:
     18         pipeout.close()
     19 
     20     return output
     21 
     22 
     23 if sys.platform == 'win32':
     24     APACHE_PATH = 'httpd'
     25 else:
     26     APACHE_PATH = 'apache'
     27 CONF_PATH = 'test_mw.conf'
     28 conf_modwsgi = '\n# Apache2 server conf file for testing CherryPy with modpython_gateway.\n\nServerName 127.0.0.1\nDocumentRoot "/"\nListen %(port)s\n\nAllowEncodedSlashes On\nLoadModule rewrite_module modules/mod_rewrite.so\nRewriteEngine on\nRewriteMap escaping int:escape\n\nLoadModule log_config_module modules/mod_log_config.so\nLogFormat "%%h %%l %%u %%t \\"%%r\\" %%>s %%b \\"%%{Referer}i\\" \\"%%{User-agent}i\\"" combined\nCustomLog "%(curdir)s/apache.access.log" combined\nErrorLog "%(curdir)s/apache.error.log"\nLogLevel debug\n\nLoadModule wsgi_module modules/mod_wsgi.so\nLoadModule env_module modules/mod_env.so\n\nWSGIScriptAlias / "%(curdir)s/modwsgi.py"\nSetEnv testmod %(testmod)s\n'
     29 
     30 class ModWSGISupervisor(helper.Supervisor):
     31     using_apache = True
     32     using_wsgi = True
     33     template = conf_modwsgi
     34 
     35     def __str__(self):
     36         return 'ModWSGI Server on %s:%s' % (self.host, self.port)
     37 
     38     def start(self, modulename):
     39         mpconf = CONF_PATH
     40         if not os.path.isabs(mpconf):
     41             mpconf = os.path.join(curdir, mpconf)
     42         f = open(mpconf, 'wb')
     43         try:
     44             output = self.template % {'port': self.port,
     45              'testmod': modulename,
     46              'curdir': curdir}
     47             f.write(output)
     48         finally:
     49             f.close()
     50 
     51         result = read_process(APACHE_PATH, '-k start -f %s' % mpconf)
     52         if result:
     53             print result
     54         cherrypy._cpserver.wait_for_occupied_port('127.0.0.1', self.port)
     55         webtest.openURL('/ihopetheresnodefault', port=self.port)
     56         time.sleep(1)
     57 
     58     def stop(self):
     59         read_process(APACHE_PATH, '-k stop')
     60 
     61 
     62 loaded = False
     63 
     64 def application(environ, start_response):
     65     global loaded
     66     import cherrypy
     67     if not loaded:
     68         loaded = True
     69         modname = 'cherrypy.test.' + environ['testmod']
     70         mod = __import__(modname, globals(), locals(), [''])
     71         mod.setup_server()
     72         cherrypy.config.update({'log.error_file': os.path.join(curdir, 'test.error.log'),
     73          'log.access_file': os.path.join(curdir, 'test.access.log'),
     74          'environment': 'test_suite',
     75          'engine.SIGHUP': None,
     76          'engine.SIGTERM': None})
     77     return cherrypy.tree(environ, start_response)