• 2016/09/18


    1. Python视频

      B. 装饰器

      多层装饰器

    USER_INFO = {}
    
    
    def check_login(func):
    	def inner(*args, **kwargs):
    		if USER_INFO.get('is_login', None):
    			ret = func(*args, **kwargs)
    			return ret
    		else:
    			print('please login')
    	return inner
    
    
    def check_admin(func):
    	def inner(*args, **kwargs):
    		if USER_INFO.get('type', None) == 2:
    			ret = func(*args, **kwargs)
    			return ret
    		else:
    			print('no permission')
    	return inner
    
    
    @check_login
    @check_admin
    def index():		# manager
    	print('Index')
    
    
    def home():			# user
    	print('home')
    
    
    def login():
    	user = input('input username
    >>>')
    	pwd = input('input password
    >>>')
    	if user == 'admin' and pwd == 'admin':
    		USER_INFO['is_login'] = True
    		USER_INFO['type'] = 2
    	else:
    		if user == 'wayne' and pwd == 'phuck':
    			USER_INFO['is_login'] = True
    			USER_INFO['type'] = 1
    
    
    def main():
    	while True:
    		inp = input('1.login 2.information 3.management
    >>>')
    		if inp == '1':
    			login()
    		elif inp == '2':
    			home()
    		elif inp == '3':
    			index()
    
    
    main()
    
  • 相关阅读:
    HDU 1425:sort
    HDU 1021:Fibonacci Again
    HDU 2035:人见人爱A^B
    HDU 1061:Rightmost Digit
    HDU 1005:Number Sequence
    HDU 1008:Elevator
    HDU 1004:Let the Balloon Rise
    HDU 2018:母牛的故事
    java推荐书籍及下载
    VC6.0 快捷键
  • 原文地址:https://www.cnblogs.com/wnzhong/p/5883766.html
Copyright © 2020-2023  润新知