1
|
|
|
from groundwork.util import gw_get |
2
|
|
|
|
3
|
|
|
|
4
|
|
|
class RouteManagerPlugin: |
5
|
|
|
|
6
|
|
|
def __init__(self, plugin): |
7
|
|
|
self.plugin = plugin |
8
|
|
|
self.log = plugin.log |
9
|
|
|
self.app = plugin.app |
10
|
|
|
|
11
|
|
|
def register(self, url, methods, endpoint, context=None, name=None, description=None): |
12
|
|
|
return self.app.web.routes.register(url, methods, endpoint, self.plugin, context, name, description) |
13
|
|
|
|
14
|
|
|
|
15
|
|
|
class RouteManagerApplication: |
16
|
|
|
def __init__(self, app): |
17
|
|
|
self._routes = {} |
18
|
|
|
self.app = app |
19
|
|
|
|
20
|
|
|
def register(self, url, methods, endpoint, plugin, context=None, name=None, description=None,): |
21
|
|
|
if context is None and self.app.web.contexts.default_context is None: |
22
|
|
|
raise RuntimeError("Context not give and no default context is available.") |
23
|
|
|
|
24
|
|
|
if context is None: |
25
|
|
|
context = self.app.web.contexts.default_context.name |
26
|
|
|
|
27
|
|
|
if name not in self._routes.keys(): |
28
|
|
|
self._routes[name] = Route(url, methods, endpoint, context, name, description, plugin) |
29
|
|
|
|
30
|
|
|
for provider in self.app.web.providers.get(): |
31
|
|
|
provider.instance.register_route() |
32
|
|
|
|
33
|
|
|
def get(self, name=None, plugin=None): |
34
|
|
|
return gw_get(self._routes, name, plugin) |
35
|
|
|
|
36
|
|
|
|
37
|
|
|
class Route: |
38
|
|
|
""" |
39
|
|
|
""" |
40
|
|
|
def __init__(self, url, methods, endpoint, context, name, description, plugin): |
41
|
|
|
self.url = url |
42
|
|
|
self.methods = methods |
43
|
|
|
self.endpoint = endpoint |
44
|
|
|
self.context = context |
45
|
|
|
self.name = name |
46
|
|
|
self.description = description |
47
|
|
|
self.plugin = plugin |
48
|
|
|
|
49
|
|
|
|