码迷,mamicode.com
首页 > 其他好文 > 详细

2016/09/18

时间:2016-09-19 07:52:39      阅读:159      评论:0      收藏:0      [点我收藏+]

标签:

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\n>>>‘)
	pwd = input(‘input password\n>>>‘)
	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\n>>>‘)
		if inp == ‘1‘:
			login()
		elif inp == ‘2‘:
			home()
		elif inp == ‘3‘:
			index()


main()

 

2016/09/18

标签:

原文地址:http://www.cnblogs.com/wnzhong/p/5883766.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!