#decorator意思:1.装饰器 2.语法糖import timeuser,passwd='qi','123'def auth(func): def wrappper(*args, **kwargs): username = input('Username:').strip() password = input('password:').strip() if user == username and passwd == password: print('\033[32;1mUser has passed authentication\033[0m') res = func(*args, **kwargs)#from home print('---after authentiction') return res #func(*args, **kwargs)#如果将以上三步换成本步,则打印不出from home,可以换成 return func(*args, **kwargs) else: exit('\033[31;1mInvalid username or password\033[0m') return wrappperdef index():#首页(不需要登录) print('Welcome to index page!')@authdef home(auth_type='local'):#主页(需要登录) print('Welcome to home page!') return 'from home'@authdef bbs(auth_type='ldap'):#论坛页(不需要登录 ) print('Welcome to bbs page!')index()print(home())#调用home相当于调用wrapper()bbs()