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

modpy.py (3305B)


      1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\carbon\common\lib\cherrypy\test\modpy.py
      2 import os
      3 curdir = os.path.join(os.getcwd(), os.path.dirname(__file__))
      4 import re
      5 import time
      6 from cherrypy.test import helper
      7 
      8 def read_process(cmd, args = ''):
      9     pipein, pipeout = os.popen4('%s %s' % (cmd, args))
     10     try:
     11         firstline = pipeout.readline()
     12         if re.search('(not recognized|No such file|not found)', firstline, re.IGNORECASE):
     13             raise IOError('%s must be on your system path.' % cmd)
     14         output = firstline + pipeout.read()
     15     finally:
     16         pipeout.close()
     17 
     18     return output
     19 
     20 
     21 APACHE_PATH = 'httpd'
     22 CONF_PATH = 'test_mp.conf'
     23 conf_modpython_gateway = '\n# Apache2 server conf file for testing CherryPy with modpython_gateway.\n\nServerName 127.0.0.1\nDocumentRoot "/"\nListen %(port)s\nLoadModule python_module modules/mod_python.so\n\nSetHandler python-program\nPythonFixupHandler cherrypy.test.modpy::wsgisetup\nPythonOption testmod %(modulename)s\nPythonHandler modpython_gateway::handler\nPythonOption wsgi.application cherrypy::tree\nPythonOption socket_host %(host)s\nPythonDebug On\n'
     24 conf_cpmodpy = '\n# Apache2 server conf file for testing CherryPy with _cpmodpy.\n\nServerName 127.0.0.1\nDocumentRoot "/"\nListen %(port)s\nLoadModule python_module modules/mod_python.so\n\nSetHandler python-program\nPythonFixupHandler cherrypy.test.modpy::cpmodpysetup\nPythonHandler cherrypy._cpmodpy::handler\nPythonOption cherrypy.setup cherrypy.test.%(modulename)s::setup_server\nPythonOption socket_host %(host)s\nPythonDebug On\n'
     25 
     26 class ModPythonSupervisor(helper.Supervisor):
     27     using_apache = True
     28     using_wsgi = False
     29     template = None
     30 
     31     def __str__(self):
     32         return 'ModPython Server on %s:%s' % (self.host, self.port)
     33 
     34     def start(self, modulename):
     35         mpconf = CONF_PATH
     36         if not os.path.isabs(mpconf):
     37             mpconf = os.path.join(curdir, mpconf)
     38         f = open(mpconf, 'wb')
     39         try:
     40             f.write(self.template % {'port': self.port,
     41              'modulename': modulename,
     42              'host': self.host})
     43         finally:
     44             f.close()
     45 
     46         result = read_process(APACHE_PATH, '-k start -f %s' % mpconf)
     47         if result:
     48             print result
     49 
     50     def stop(self):
     51         read_process(APACHE_PATH, '-k stop')
     52 
     53 
     54 loaded = False
     55 
     56 def wsgisetup(req):
     57     global loaded
     58     if not loaded:
     59         loaded = True
     60         options = req.get_options()
     61         import cherrypy
     62         cherrypy.config.update({'log.error_file': os.path.join(curdir, 'test.log'),
     63          'environment': 'test_suite',
     64          'server.socket_host': options['socket_host']})
     65         modname = options['testmod']
     66         mod = __import__(modname, globals(), locals(), [''])
     67         mod.setup_server()
     68         cherrypy.server.unsubscribe()
     69         cherrypy.engine.start()
     70     from mod_python import apache
     71     return apache.OK
     72 
     73 
     74 def cpmodpysetup(req):
     75     global loaded
     76     if not loaded:
     77         loaded = True
     78         options = req.get_options()
     79         import cherrypy
     80         cherrypy.config.update({'log.error_file': os.path.join(curdir, 'test.log'),
     81          'environment': 'test_suite',
     82          'server.socket_host': options['socket_host']})
     83     from mod_python import apache
     84     return apache.OK