python学习(day4)
import timeuser,pwd = "alex","123"
def auth(auth_type):
def outer_wrapper(func):
print("auth func:",auth_type)
def wrapper(*args,**kwargs):
print("auth func args:",*args,**kwargs)
if auth_type=="local":
username = input("username:").strip()
password = input("password:").strip()
if user == username and pwd ==password:
print("\033[32;1m user has passed authentication\033[0m")
res = func(*args,**kwargs)
print("-----c----")
return res
else:
exit("\033[31;1m invalid username or password\033[0m")
elif auth_type=="ldap":
print("ldap,不会")
return wrapper
return outer_wrapper
def index():
print("welcome to index page")
@auth(auth_type="local")
def home():# home = wrapper()
print("welcome to home page")
return print("from home")
@auth(auth_type="ldap")
def bbs():
print("welcome to bbs page")
index()
home()#wrapper()
bbs()
页:
[1]