码迷,mamicode.com
首页 > 其他好文 > 详细

装饰器

时间:2018-09-04 13:34:43      阅读:154      评论:0      收藏:0      [点我收藏+]

标签:auth   turn   use   port   local   body   dap   name   lse   



 
 


import time

user,password=‘abc‘,‘abc123‘
def auth (auth_type):
def out_warpper(funk):
def warpper(*args,**kwargs):
if auth_type==‘local‘:
username =input(‘username‘).strip()
password =input("password").strip()
if username==user and password==password:
print("\033[31;1m welcome to username in the home \033[0m")
res=funk(*args,**kwargs)
return res
else:print("\033[31;1m Invalid username or password\033[0m")
elif auth_type=="ldap":
print("逗你玩呢,没有密码,哈哈哈")
return warpper
return out_warpper

def index():
print("welcome to index page")
@auth(auth_type="local") # home = wrapper()
def home():
print("welcome to home page")
return "from home"
@auth(auth_type="ldap")
def bbs():
print("welcome to bbs page")
index()
print(home()) #wrapper()
bbs()

装饰器

标签:auth   turn   use   port   local   body   dap   name   lse   

原文地址:https://www.cnblogs.com/nyqxiaoqiang/p/9583648.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!