-
Notifications
You must be signed in to change notification settings - Fork 3
/
test.py
98 lines (79 loc) · 2.43 KB
/
test.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
from typing import Any
from pyouter.app import App
from pyouter.router import Router
import json
import asyncio
import time
async def hello(config, options):
print("hello function")
def hello_sync(config, options):
print("hello sync")
class Hello:
def __init__(self, value) -> None:
self.value = value
# Router class SHOULD provider method: `run(self, config, options)`
async def run(self, config, options) -> Any:
self.config = config
self.options = options
await self.inner()
async def inner(self):
print(f"run Hello, {self.value}")
await asyncio.sleep(2)
print(f"hello class object, self.options.debug:{self.options.debug}, sleep 2s")
if self.options.debug:
print(f'debug, {self.value}')
class Hello_Sync:
def __init__(self, value) -> None:
self.value = value
# Router class SHOULD provider method: `run(self, config, options)`
def run(self, config, options) -> Any:
self.config = config
self.options = options
self.inner()
def inner(self):
print(f"run Hello_Sync, {self.value}")
time.sleep(self.value)
print(f"hello class object, self.options.debug:{self.options.debug}, sleep {self.value}s")
if self.options.debug:
print(f'debug, {self.value}')
if __name__=="__main__":
'''
Usage:
## execute:
* python test.py test.hello.func
* python test.py test.hello.obj
* python test.py test
## dump router path only:
* python test.py test.hello -i
* python test.py test.hello --insepect
## dump router path and execute:
* python test.py test.hello -v
* python test.py test.hello --view
'''
app = App(
config='config.json',
)
app.option(
'-d', '--debug',
dest='debug',
action="store_true",
help='debug'
)
app.use(
router=Router(
test=Router(
hello=Router(
func=hello,
obj=Hello("world"),
obj2=Hello_Sync(10)
),
hello2=hello,
hello3=Router(
func=hello_sync,
obj=Hello("world"),
obj2=Hello_Sync(20),
)
)
)
)
app.run()