cherrypy update

fixes #3348
This commit is contained in:
AdeHub
2024-12-07 19:56:21 +13:00
parent 94d62430a0
commit a09e91ff8a
28 changed files with 512 additions and 108 deletions
+10
View File
@@ -72,6 +72,7 @@ from cherrypy.lib import httputil
def setup(req):
"""Execute pre-initialization functions."""
from mod_python import apache
# Run any setup functions defined by a "PythonOption cherrypy.setup"
@@ -140,6 +141,7 @@ _isSetUp = False
def handler(req):
"""Invoke the HTTP handler."""
from mod_python import apache
try:
global _isSetUp
@@ -251,6 +253,7 @@ def handler(req):
def send_response(req, status, headers, body, stream=False):
"""Send the HTTP response to the client."""
# Set response status
req.status = int(status[:3])
@@ -276,17 +279,20 @@ try:
import subprocess
def popen(fullcmd):
"""Invoke a subprocess via :mod:`subprocess`."""
p = subprocess.Popen(fullcmd, shell=True,
stdout=subprocess.PIPE, stderr=subprocess.STDOUT,
close_fds=True)
return p.stdout
except ImportError:
def popen(fullcmd):
"""Invoke a subprocess via :mod:`os`."""
pipein, pipeout = os.popen4(fullcmd)
return pipeout
def read_process(cmd, args=''):
"""Return a subprocess standard output."""
fullcmd = '%s %s' % (cmd, args)
pipeout = popen(fullcmd)
try:
@@ -305,6 +311,7 @@ def read_process(cmd, args=''):
class ModPythonServer(object):
"""A server wrapper for ``mod_python``."""
template = """
# Apache2 server configuration file for running CherryPy with mod_python.
@@ -323,6 +330,7 @@ LoadModule python_module modules/mod_python.so
def __init__(self, loc='/', port=80, opts=None, apache_path='apache',
handler='cherrypy._cpmodpy::handler'):
"""Initialize a ``mod_python`` server."""
self.loc = loc
self.port = port
self.opts = opts
@@ -330,6 +338,7 @@ LoadModule python_module modules/mod_python.so
self.handler = handler
def start(self):
"""Start an Apache2/httpd server."""
opts = ''.join([' PythonOption %s %s\n' % (k, v)
for k, v in self.opts])
conf_data = self.template % {'port': self.port,
@@ -347,5 +356,6 @@ LoadModule python_module modules/mod_python.so
return response
def stop(self):
"""Stop an Apache2/httpd server."""
os.popen('apache -k stop')
self.ready = False