commit | author | age
|
881ffe
|
1 |
import functools |
JK |
2 |
|
|
3 |
import flask |
|
4 |
from werkzeug.local import LocalProxy |
|
5 |
|
|
6 |
|
|
7 |
class InputValidationException(Exception): |
|
8 |
pass |
|
9 |
|
|
10 |
|
|
11 |
class Blueprint(flask.Blueprint): |
|
12 |
logger = LocalProxy(lambda: flask.current_app.logger) |
|
13 |
|
|
14 |
def route(self, route, **options): |
|
15 |
parent_function_wrapper = super().route(route, **options) |
|
16 |
|
|
17 |
def newFunctionWrapper(func): |
|
18 |
@functools.wraps(func) |
|
19 |
def newFunction(): |
|
20 |
try: |
|
21 |
result = func() |
|
22 |
except InputValidationException as e: |
|
23 |
self.logger.error(e) |
|
24 |
return { |
|
25 |
'Err': e.args[0], |
|
26 |
} |
|
27 |
return result |
|
28 |
|
|
29 |
return parent_function_wrapper(newFunction) |
|
30 |
|
|
31 |
return newFunctionWrapper |
|
32 |
|
|
33 |
|
|
34 |
app = Blueprint('Plugin', __name__) |
|
35 |
|
|
36 |
functions = [] |
|
37 |
|
|
38 |
|
|
39 |
@app.route('/Plugin.Activate', methods=['POST']) |
|
40 |
def Activate(): |
|
41 |
return { |
|
42 |
'Implements': functions, |
|
43 |
} |
|
44 |
|
|
45 |
|
|
46 |
__all__ = ['InputValidationException', 'Blueprint', 'app', 'functions'] |