Function Review 05

= {login_dic "username": None, "In Flag": False}
MSG = "" "Please select App:
QQ
micro-channel
vibrato
mailbox
" ""

INPUT = chose (MSG) .upper ()
DEF the auth (the argv):
DEF warpper (F):
DEF Inner (* args, ** kwargs):
IF login_dic [ "In Flag"]:
F (* args, ** kwargs)
the else:
IF argv == "QQ":
Print ( "Welcome to QQ")
the User = the iNPUT ( "Please enter account:")
password = the iNPUT ( "Please enter your password:")
IF the User == "alex" and password = = "alex123":
login_dic [ "In Flag"] = True
login_dic [ "username"] = User
F (* args, ** kwargs)
the else:
Print ( "account number or password error")
elif the argv == "micro-channel":
Print ( "Welcome to the micro-letter")
the User = the iNPUT ( "Please enter account:")
password = the iNPUT ( "Please enter your password:")
IF the User == "alex123" and password == "alex123456":
login_dic["flag"] = True
login_dic["username"] = user
f (* args, ** kwargs)
the else:
Print ( "Account or password error")
elif argv == "vibrato":
Print ( "Welcome vibrato")
the User = the INPUT ( "Please enter account:")
password = input ( "Please enter your password:")
IF the User == "alex456" and password == "alex456123":
login_dic [ "Flag"] = True
login_dic [ "username"] = the User
f (* args, ** kwargs)
the else:
Print ( "account or password error")
the else:
Print ( "Welcome to the mailbox")
the User = the iNPUT ( "Please enter account:")
password = the iNPUT ( "Please enter your password:")
IF the User == "alex @ qq.com "and password ==" alex123 ":
login_dic [" In Flag "] = True
login_dic [" username "] The User =
f (* args, ** kwargs)
the else:
Print ( "Account or password error")
return Inner
return wrapper

@auth (chose)
DEF foo ():
Print ( "This is a decorated function")
foo ()

@auth (chose) equivalent to the following two lines of code deconstruction

wrapper = auth(chose)

foo = wrapper(foo)

2. Decorative a plurality of decorative function
DEF wrapper1 (FUNC):
DEF inner1 (* args, ** kwargs):
Print (. 1)
FUNC (* args, ** kwargs)
Print (. 11)
return inner1

def wrapper2(func):
def inner2(*args,**kwargs):
print(2)
func(*args,**kwargs)
print(22)
return inner2

def wrapper3(func):
def inner3(*args,**kwargs):
print(3)
func(*args,**kwargs)
print(33)
return inner3

wrapper3 @
@ wrapper2
@ wrapper1
DEF foo ():
Print ( "This is a decorated function")

foo()

3

2
. 1
This is a function to be decorated
. 11
22 is
33 is

Guess you like

Origin www.cnblogs.com/-777/p/11240930.html