Add bottle class proto (and simple class method routing)
This commit is contained in:
24
aore/miscutils/bottlecl.py
Normal file
24
aore/miscutils/bottlecl.py
Normal 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)
|
||||
Reference in New Issue
Block a user