-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathroute.py
More file actions
54 lines (48 loc) · 1.46 KB
/
route.py
File metadata and controls
54 lines (48 loc) · 1.46 KB
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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Module Description:
@Time : 2017/12/11 17:02
@Author : fengweiqian
"""
import json
import sys
import traceback
from app.action.action_base import lazy_import
if sys.version[0] == "2":
from urllib import unquote
else:
from urllib.parse import unquote
def get_params(request):
"""
取出参数
:return: ip, 参数
"""
params = ''
if request.method == 'GET':
params = unquote(request.query_string).decode('utf8')
params = json.loads(params)
elif request.method == 'POST':
params = request.json
return params
async def exec_action(ip,request):
try:
# 获取参数
params = get_params(request)
action_id = params.get('ActionId', 0)
print("ActionId:", action_id, " params:", params)
# 反射实例化操作
action_xxx = lazy_import(action_id)
print("---------import--2-------------------------------")
class_obj = action_xxx(params, ip) # 类名为class_name的对象
print("-----------do_action--3-----------------------------")
result = await class_obj.exec_action() # 执行对象的exec_action方法d
except Exception as e:
traceback.print_exc()
print("--------------------e---4-------------------",e)
result = "exec_action exception"
# res = json.dumps(result)
from sanic.response import json
print(result)
res = json(result)
return res