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()

  • 相关阅读:
    ~虚拟现实论文~
    Vega Prime Distributed 模块的中文总结
    怎样在程序中使用vgPicker移动物体
    黑客档案
    在VBA中连接SQL SERVER数据库
    VC中调用Matlab引擎的设置
    在VB应用程序中单击按钮打开word文档
    matlab调用ansys的方法
    实现VC与Matcom的接口步骤
    vega编程中文资料
  • 原文地址:https://www.cnblogs.com/luckerzhang/p/9305355.html
Copyright © 2011-2022 走看看