import time
current_user={'user':None}
def auth(engine = 'file'):
def deco(func): #func=最初始的index和最初始的home
def wrapper(*args,**kwargs):
if current_user['user']:
#如果成立说明current_user里面已经有用户信息,说明用户已经登录过,满足条件
#即会执行调用index home函数
res = func(*args, **kwargs) #调用最原始的index 同样也调用最原始的home,
return res user=input('输入你的用户名:').strip()
pwd=input('输入你的密码:').strip()
if engine == 'file':
#基于文件的认证
if user == 'yangzhizong' and pwd == '123':
print('认证成功')
#记录用户登录状态
current_user['user']=user
res = func(*args, **kwargs)
return res
else:
print('用户名密码错误') elif engine == 'mysql':
print('基于mysql的认证')
elif engine == 'idap':
print('基于idap的认证')
else:
print('无法识别认证来源') return wrapper
return deco # @timmer 2层是 3层此时可以理解为:@auth(engine = 'file')
#可以理解为上面这种情况
# x=auth(engine='file')
# @x
@auth(engine='file') #拿到了deco的返回值,最后调用index加(),输出结果 #deco #index=deco(index) #index=wrapper
def index():
time.sleep(1)
print('welcome to index page') @auth(engine='file')
def home(name):
print('welcome %s to home page'%name )
time.sleep(0.5) index()
home('yangzhizong')

最新文章

  1. 回忆:#define的用法
  2. hadoop集群安装无密码登录
  3. ISPA
  4. 慕课网-Java入门第一季-6-10 练习题
  5. [Unity] 精灵动画制作中需要注意的一些问题
  6. ThreadPool原理介绍
  7. Shallow Size 和 Retained Size
  8. 图像处理工具包ImagXpress中如何定义查看器的属性
  9. 浅析 GRUB 如何加载 linux kernel
  10. 【原】 Spark中Worker源码分析(二)
  11. Linq to Sql语法及实例大全
  12. asp.net 的那点事(1、当用户在浏览器地址栏输入了网址后,发生了什么?)
  13. 交互设计师谈颠覆式创新 | Think different
  14. include和 merge
  15. 学习Sass之安装篇
  16. ABP官方文档翻译 4.1 应用服务
  17. 201421123042 《Java程序设计》第6周学习总结
  18. php使用protobuf3
  19. jquery 取id模糊查询
  20. dRMT: Disaggregated Programmable Switching, SIGCOMM17

热门文章

  1. Android 虚拟导航挡住应用底部解决方案(屏幕底部的三个按键)
  2. 利用C#脚本来处理Excel
  3. 数据库limit子句
  4. Literals
  5. Ubuntu下apt-get与pip安装命令的区别
  6. vue跨域处理(vue项目中baseUrl设置问题)
  7. dev gridview columns代码管理
  8. 【思维题 kmp 构造】bzoj4974: [Lydsy1708月赛]字符串大师
  9. [LUOGU]P1508 Likecloud-吃、吃、吃
  10. C#基础-数组-冒泡排序