September 28, 2018 function part4 multiple adorners and iterators

Source: Internet
Author: User
Tags ldap

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.