1
0
mirror of https://github.com/Tygs/0bin.git synced 2023-08-10 21:13:00 +03:00
0bin/libs/cherrypy/_cpwsgi_server.py

71 lines
3.0 KiB
Python
Raw Normal View History

2012-04-26 23:19:12 +04:00
"""WSGI server interface (see PEP 333). This adds some CP-specific bits to
the framework-agnostic wsgiserver package.
"""
import sys
import cherrypy
from cherrypy import wsgiserver
class CPWSGIServer(wsgiserver.CherryPyWSGIServer):
2015-05-10 20:19:02 +03:00
2012-04-26 23:19:12 +04:00
"""Wrapper for wsgiserver.CherryPyWSGIServer.
2015-05-10 20:19:02 +03:00
2012-04-26 23:19:12 +04:00
wsgiserver has been designed to not reference CherryPy in any way,
so that it can be used in other frameworks and applications. Therefore,
we wrap it here, so we can set our own mount points from cherrypy.tree
and apply some attributes from config -> cherrypy.server -> wsgiserver.
"""
2015-05-10 20:19:02 +03:00
2012-04-26 23:19:12 +04:00
def __init__(self, server_adapter=cherrypy.server):
self.server_adapter = server_adapter
2015-05-10 20:19:02 +03:00
self.max_request_header_size = (
self.server_adapter.max_request_header_size or 0
)
self.max_request_body_size = (
self.server_adapter.max_request_body_size or 0
)
2012-04-26 23:19:12 +04:00
server_name = (self.server_adapter.socket_host or
self.server_adapter.socket_file or
None)
2015-05-10 20:19:02 +03:00
2012-04-26 23:19:12 +04:00
self.wsgi_version = self.server_adapter.wsgi_version
s = wsgiserver.CherryPyWSGIServer
s.__init__(self, server_adapter.bind_addr, cherrypy.tree,
self.server_adapter.thread_pool,
server_name,
2015-05-10 20:19:02 +03:00
max=self.server_adapter.thread_pool_max,
request_queue_size=self.server_adapter.socket_queue_size,
timeout=self.server_adapter.socket_timeout,
shutdown_timeout=self.server_adapter.shutdown_timeout,
accepted_queue_size=self.server_adapter.accepted_queue_size,
accepted_queue_timeout=self.server_adapter.accepted_queue_timeout,
2012-04-26 23:19:12 +04:00
)
self.protocol = self.server_adapter.protocol_version
self.nodelay = self.server_adapter.nodelay
if sys.version_info >= (3, 0):
ssl_module = self.server_adapter.ssl_module or 'builtin'
else:
ssl_module = self.server_adapter.ssl_module or 'pyopenssl'
if self.server_adapter.ssl_context:
adapter_class = wsgiserver.get_ssl_adapter_class(ssl_module)
self.ssl_adapter = adapter_class(
self.server_adapter.ssl_certificate,
self.server_adapter.ssl_private_key,
self.server_adapter.ssl_certificate_chain)
self.ssl_adapter.context = self.server_adapter.ssl_context
elif self.server_adapter.ssl_certificate:
adapter_class = wsgiserver.get_ssl_adapter_class(ssl_module)
self.ssl_adapter = adapter_class(
self.server_adapter.ssl_certificate,
self.server_adapter.ssl_private_key,
self.server_adapter.ssl_certificate_chain)
2015-05-10 20:19:02 +03:00
self.stats['Enabled'] = getattr(
self.server_adapter, 'statistics', False)
2012-04-26 23:19:12 +04:00
def error_log(self, msg="", level=20, traceback=False):
cherrypy.engine.log(msg, level, traceback)