Python 装饰器
# -*- coding:utf-8 -*- import time import api import auth ''' Python 装饰器 AOP 的编程思想 ''' # 对修改是封闭的,对扩展是开放的 # 当需求变更了,尽量不去改方法,类内部的实现 # 可以接受定义是的复杂,只要调用时足够简单(绝对不能接受调用的复杂) def print_current_time(func): print(time.time()) func() # print_current_time(f1) # print_current_time(f2) def decorator(func): def wrapper(*args, **kw): print(time.time()) func(*args, **kw) return wrapper @decorator def f1(func_name): print("function name is: " + func_name) @decorator def f2(func_name1, func_name2): print("function name is: " + func_name1) print("function name is: " + func_name2) @decorator def f3(func_name1, func_name2, **kw): print("function name is: " + func_name1) print("function name is: " + func_name2) print(kw) # 调用 f1("test func") f2('test func1', 'test fun2') f3('test func1', 'a', a=1, b=2, c='123') @api.route('./get', methods=['GEt']) def test_java_script_http(): p = request.args.get('name') return p, 200 @api.route('./get', methods=['GEt']) @auth.login_required def get_psw(): p = request.args.get('psw') r = generate_password_hash(p) return 'aaaaaa', 200