python嵌套(1)

#__author__ = "Sooele"
import time
user,passwd = 'sooele','abc123' #
def auth(auth_type): #自定义函数auth(auth_type),auth_type是auth函数的值
    print("auth func:",auth_type) #下面@auth函数的嵌套跳回
    def outer_wrapper(func):#定义函数outer_wrapper(func),func是函数的值
        def wrapper(*args, **kwargs): #定义wrapper函数
            print("wrapper func args:", *args, **kwargs) #输出
            if auth_type == "local": #如果
                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 authenticaion ")
                    return res
                else:
                    exit("\033[31;1mInvalid username or password\033[0m")
            elif auth_type == "ldap":
                print("搞毛线ldap,不会。。。。")

        return wrapper #返回wrapper函数的值
    return outer_wrapper #返回outer_wrapper函数的值

def index(): #定义函数index
    print("welcome to index page")
@auth(auth_type="local") # home = wrapper()    #嵌套函数auth
def home():
    print("welcome to home  page")
    return "from home"

@auth(auth_type="ldap")  #嵌套使用auth函数
def bbs():
    print("welcome to bbs  page")
index()
print("````````````````````````````")

print(home()) #wrapper()
bbs()