zoukankan      html  css  js  c++  java
  • decorator高潮版

    import time

    user,passwd = 'zaizai','abc123'

    def auth(auth_type):

          print("auth func:",auth_type)

          def outer_wrapper(func):

                 def wrapper(*args,**kwargs)

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

                       if auth_type == "local":

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

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

                          if user == username and passwd == password:

                                 print("User has passed authtication")

                                 res = func(*args,**kwargs)

                                 return res

                           else:

                                  exit("Invalid username or password")

                       elif auth_type == "ldap"

                               print("搞毛线ldap")

                 return wrapper      

          return outer_wrapper

    def index():

          print("welcome to index page")

    @auth(auth_type"local") 

    def home():

          print("welcome to home page")

          return "from home"

    @auth(auth_type="ldap")

    def bbs():

          print("welcome to bbs page")

    index()

    print(home())

    bbs()

  • 相关阅读:
    c++ 中bool 的默认值
    cocos2d CCLOG格式符号表
    c++数组指针bug
    cocos2d-x-2.2.6创建工程
    Nape实现坐标旋转角度回弹
    haxe 中使用音效
    haxe 嵌入swf 读取里面的内容
    haxe 配置
    Spring Tool Suite(STS)基本安装配置
    git提交忽略文件.gitignore内容
  • 原文地址:https://www.cnblogs.com/zaizaiaipython/p/7819546.html
Copyright © 2011-2022 走看看