python 有参数的装饰器
2024-08-31 22:04:02
怎么样为装饰器加参数
import time
current_user = {'user':None} def auth(engine = "file")
def deco(func):
def wrapper(*args,**kwargs):
if current_user['user']:
#已经登录过
res = func(*args,**kwargs)
return res
user = input("username>>>:").strip()
pwd = input("password>>>:").strip()
if engine == 'file': #基于文件的认证
if user == “egon‘ and pwd == "123":
print('login successful')
current_user['user'] = user
res = func(*args,**kwargs)
return res
else:
print('user or password error')
elif engine == 'mysql':
print('基于MySQL的认证') elif engine == 'mysql':
print('基于MySQL的认证')
elif engine == 'ldap':
print('基于ldap的认证')
else:
print('无法识别认证来源')
return wrapper
return deco @auth(engine = ”mysql“) def index():
print('welcome to index page')
time.sleep(1) index()
最新文章
- Java技能树
- FPGA低级建模---按键去抖动
- Anliven - 你的学习为何如此低效?!
- Spring3 整合MyBatis3 配置多数据源 动态选择SqlSessionFactory
- 161205、win10安装mysql5.7.16数据库
- HTML to DOM
- Xamarin 安装体验
- DecimalFormat
- oracle中的turnc,round,floor,ceil,coalesce函数
- oracle java连接配置
- Unsupervised pre-training
- JavaSE assert断言的学习
- day19 十九、ATM+购物车
- JAVA SpringBoot 项目打成jar包供第三方引用自动配置(Spring发现)解决方案
- MHA-手动Failover流程(传统复制&;GTID复制)
- [蓝桥杯]ALGO-97.算法训练_排序
- 地图调起URI API(通过连接直接调用百度地图)
- nginx中server的匹配顺序
- hbase 学习(十二)非mapreduce生成Hfile,然后导入hbase当中
- mysql8.0 安装
热门文章
- python时间 time模块和datetime模块
- SP Flash Tool版本对应MTK处理器型号速查(SP Flash Tool Download)
- 关于distinct的compare参数的使用
- 【51nod1220】约数之和
- jquery keypress() 方法 语法
- 【POJ1011】Sticks
- HDU 3468:A Simple Problem with Integers(线段树+延迟标记)
- Alibaba DataX 源码编译
- Excel导入导出工具(简单、好用且轻量级的海量Excel文件导入导出解决方案.)
- web 多屏互动显示方案