zoukankan      html  css  js  c++  java
  • Python入门:装饰器案例3

    import time

    user,passwd="LIly","abc123"

    def auth(auth_type):

      print("auth func:",auth_type)

      def outwrapper(func):

        def wrapper(*args,**kwargs):

          print("wrapper func args:", *args, **kwargs)

          if auth_type=="local":

            username=input("username:").strip()

            password=input("password:").strip()

            if username==user and password==passwd :

              print("33[32:1mUser has passed authentication33[0m")

              res=func(*args,**kwargs) #from home

              return res

            else:

              exit("33[31;1mInvalid username or password33[0m")

          elif auth_type=="ldap":

            print("搞毛线ldap,不会。。。。")

            

           return wrapper

        return outwrapper

    def index():

      print("welcome to index page")

    @auth(auth_type="local")

    def home():

      print("welcome to home page")

      return "from home"

    @auth(auth_type="ladp") # home = wrapper()

    def bbs():

      print("welcome to bbs page")

    index()

    print(home())  #wrapper

    bbs()

  • 相关阅读:
    关于API微服务网关
    适用于企业的API管理平台
    简单的api测试
    Json,2020年api数据格式的Top 1
    API文档之团队协作
    如何进行API测试以提高程序质量
    API接口也要监控?
    春招实习_腾讯 wxg 一面 3.27 15:00
    春招实习_腾讯一面 & 二面_3.13
    春招实习_阿里一面
  • 原文地址:https://www.cnblogs.com/luckerzhang/p/9305355.html
Copyright © 2011-2022 走看看