From 888aa8e7b8f6490015463ee370ff4026fc951b1f Mon Sep 17 00:00:00 2001 From: 06180339 Date: Sat, 28 Jan 2017 23:29:29 +0100 Subject: [PATCH] Add ServerAdapter for CherryPy >= 9 Since CherryPy >= 9, the server part of CherryPy has been extracted and named Cheroot. Thus the old CherryPy ServerAdapter does not work for CherryPy >= 9: the import fails, and the SSL part should be different too. Cheroot can be installed (git install cheroot) without CherryPy so that we can just have a CherootServer adapter in addition to the CherryPyServer adapter for the older versions. (cherry picked from commit b9229eef97ea246e3d0e0c455071d54435a1557d) Signed-off-by: Juerg Haefliger --- bottle.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/bottle.py b/bottle.py index 04ccf7da..73886a2f 100644 --- a/bottle.py +++ b/bottle.py @@ -2816,6 +2816,25 @@ def run(self, handler): # pragma: no cover server.stop() +class CherootServer(ServerAdapter): + def run(self, handler): # pragma: no cover + from cheroot import wsgi + from cheroot.ssl import builtin + self.options['bind_addr'] = (self.host, self.port) + self.options['wsgi_app'] = handler + certfile = self.options.pop('certfile', None) + keyfile = self.options.pop('keyfile', None) + chainfile = self.options.pop('chainfile', None) + server = wsgi.Server(**self.options) + if certfile and keyfile: + server.ssl_adapter = builtin.BuiltinSSLAdapter( + certfile, keyfile, chainfile) + try: + server.start() + finally: + server.stop() + + class WaitressServer(ServerAdapter): def run(self, handler): from waitress import serve