From 888aa8e7b8f6490015463ee370ff4026fc951b1f Mon Sep 17 00:00:00 2001 From: 06180339 Date: Sat, 28 Jan 2017 23:29:29 +0100 Subject: [PATCH 1/3] 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 From a3ba0eb30e7becdfe0eb83dc2babaa40847cd7d0 Mon Sep 17 00:00:00 2001 From: Marcel Hellkamp Date: Sat, 25 Mar 2017 17:59:26 +0100 Subject: [PATCH 2/3] Added 'cheroot' server adapter to list of server names, so it can be selected from the command line and by name. Alos added cheroot after cherrypy in the 'auto' adapter to make it future proof. (backported from commit 617d08a2ccca95b2e8668fef7057127049595fd9) [juergh: Adjust context.] Signed-off-by: Juerg Haefliger --- bottle.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/bottle.py b/bottle.py index 73886a2f..11121b8e 100644 --- a/bottle.py +++ b/bottle.py @@ -3002,7 +3002,9 @@ def run(self, handler): class AutoServer(ServerAdapter): """ Untested. """ - adapters = [WaitressServer, PasteServer, TwistedServer, CherryPyServer, WSGIRefServer] + adapters = [WaitressServer, PasteServer, TwistedServer, CherryPyServer, + CherootServer, WSGIRefServer] + def run(self, handler): for sa in self.adapters: try: @@ -3016,6 +3018,7 @@ def run(self, handler): 'wsgiref': WSGIRefServer, 'waitress': WaitressServer, 'cherrypy': CherryPyServer, + 'cheroot': CherootServer, 'paste': PasteServer, 'fapws3': FapwsServer, 'tornado': TornadoServer, From 6e9c55ac25993e12eb9674c4b11c8673c55cfd54 Mon Sep 17 00:00:00 2001 From: Marcel Hellkamp Date: Sat, 25 Mar 2017 17:53:27 +0100 Subject: [PATCH 3/3] Added depr warning for the outdated cherrypy server adapter. If you are using this adapter, simply switch to 'cheroot' This should fix some recent and some very old issues regarding cherrypy: fix #947 Leave explicit the maxima version supported the CherryPy (<= 9.0.0) fix #932 Add ServerAdapter (fix CherryPy ServerAdapter) fix #685 Update CherryPy SSL to use latest API and work on Py3 fix #574 Allow custom bind_addr for CherryPy (backported from commit be90814117008e6f19a2d8d5c67b876787888aa6) [juergh: Adjust context, drop modifications of test/travis-requirements.txt which does not exist in 0.12.] Signed-off-by: Juerg Haefliger --- bottle.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/bottle.py b/bottle.py index 11121b8e..60e6c9db 100644 --- a/bottle.py +++ b/bottle.py @@ -2793,7 +2793,11 @@ class server_cls(server_cls): class CherryPyServer(ServerAdapter): def run(self, handler): # pragma: no cover - from cherrypy import wsgiserver + depr(0, 13, "The wsgi server part of cherrypy was split into a new " + "project called 'cheroot'.", "Use the 'cheroot' server " + "adapter instead of cherrypy.") + from cherrypy import wsgiserver # This will fail for CherryPy >= 9 + self.options['bind_addr'] = (self.host, self.port) self.options['wsgi_app'] = handler