Add bottle class proto (and simple class method routing)

This commit is contained in:
jar3b
2016-03-12 18:24:02 +03:00
parent 3fe80ecef8
commit b0914d58f5
3 changed files with 73 additions and 44 deletions

View File

@@ -0,0 +1,24 @@
# -*- coding: utf-8 -*-
from bottle import Bottle
class BottleCL(object):
def __init__(self):
self._app = Bottle()
self.init_routes()
def init_routes(self):
pass
def add_route(self, route_path, handler):
self._app.route(route_path, callback=handler)
def add_error(self, error_code, handler):
if not self._app.error_handler:
self._app.error_handler = {error_code: handler}
else:
self._app.error_handler[error_code] = handler
def start(self, host, port):
self._app.run(host=host, port=port)