-
Notifications
You must be signed in to change notification settings - Fork 1
/
composite.py
77 lines (54 loc) · 1.95 KB
/
composite.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
"""
Composite application
"""
from twisted.web.iweb import IRequest
from ._main import main
from .dns import Application as DNSApplication
from .hello import Application as HelloApplication
from .klein import Klein, KleinRenderable
from .math import Application as MathApplication
__all__ = (
"Application",
)
class Application(object):
"""
Composite application.
Application that exposes endpoints that are handled by other applications,
thereby composing multiple applications into a single application.
"""
router = Klein()
main = classmethod(main) # type: ignore
@router.route("/")
def root(self, request: IRequest) -> KleinRenderable:
"""
Application root resource.
Responds with a message noting the nature of the application.
:param request: The request to respond to.
"""
return "This is a web application composed from multiple applications."
@router.route("/dns/", branch=True)
def dns(self, request: IRequest) -> KleinRenderable:
"""
DNS application resource.
Routes requests to :class:`.dns.Application`.
:param request: The request to respond to.
"""
return DNSApplication().router.resource()
@router.route("/hello/", branch=True)
def hello(self, request: IRequest) -> KleinRenderable:
"""
Hello application resource.
Routes requests to :class:`.hello.Application`.
:param request: The request to respond to.
"""
return HelloApplication().router.resource()
@router.route("/math/", branch=True)
def math(self, request: IRequest) -> KleinRenderable:
"""
Math application resource.
Routes requests to :class:`.math.Application`.
:param request: The request to respond to.
"""
return MathApplication().router.resource()
if __name__ == "__main__": # pragma: no cover
Application.main() # type: ignore