zoukankan      html  css  js  c++  java
  • 装饰器3


    import time

    user,passwd = 'lian','abc123'
    def auth(auth_type):
    def outer_wrapper(func):
    def wrapper(*args,**kwargs):
    if auth_type == "local":
    username = input("Username:").strip()
    password = input("Password:").strip()
    if user == username and passwd == password:
    print('33[32;1mUser has passed authentication33[0m')
    res = func(*args,**kwargs)
    print('=============')
    return res
    else:
    exit("33[32;1mInvalid username or password33[0m")
    elif auth_type == "ldap":
    print('ldap++++++')
    return wrapper
    return outer_wrapper
    def index():
    print('welcome to index page')
    @auth(auth_type="local")#home = wraper()
    def home():
    print('welcome to home page')
    return "welcome"
    @auth(auth_type="ldap")#
    def bbs():
    print("welcome to bbs page")

    index()
    print(home())
    bbs()






    welcome to index page
    Username:lian
    Password:abc123
    User has passed authentication
    welcome to home page
    =============
    welcome
    ldap++++++

  • 相关阅读:
    Vivian's Problem UVA
    Prime k-tuple UVA
    M
    Make a Crystal UVA
    Cryptography Reloaded UVALive
    Gauss Prime UVA
    Discrete Square Roots UVALive
    The Bells are Ringing UVALive
    Huge Mods UVA
    指数循环节
  • 原文地址:https://www.cnblogs.com/rongye/p/9923664.html
Copyright © 2011-2022 走看看