One or more adorners
1. When a decorated object overlays multiple adorners at the same time, the rule:
(1) The order in which the adorner is loaded is: bottom-up
(2) The order of execution of the wrapper function inside the adorner is: top-down
Import Timedef Timmer (func): #func=wrapper2 memory address def wrapper1 (*args, * *Kwargs): Print ('===================================>wrapper1 Run the') Start=time.time () Res= Func (*args, **kwargs) #===========================>jump to Wrapper2 to execute, stop=time.time () print ('run time is%s'% (Stop-start)) returnResreturnwrapper1def Auth (engine='file'): def xxx (func): # func=The memory address of the original index is Def wrapper2 (*args, * *Kwargs): Print ('===================================>wrapper2 Run the') name=input ('Username>>>:'). Strip () PWD=input ('Password>>>:'). Strip ()ifEngine = ='file': Print ('file-based authentication') ifName = ='Egon'and PWD = ='123': Print ('Login Successfull') Res= Func (*args, * *Kwargs)returnRes elif engine=='MySQL': Print ('MySQL-based authentication') elif engine=='LDAP': Print ('LDAP-based authentication') Else: Print ('the wrong authentication source') returnWrapper2returnXxx@timmer # Index=timmer (memory address of wrapper2) #index =Wrapper1 memory address @auth (engine='file'# @xxx #index =xxx (the memory address of the original index) #index =wrapper2 memory Address def index (): Print ('Welcome to Index page') Time.sleep (2) index () #wrapper1的内存地址 ()
September 28, 2018 function part4 multiple adorners and iterators