-
Notifications
You must be signed in to change notification settings - Fork 54
/
装饰器2.py
37 lines (33 loc) · 1.02 KB
/
装饰器2.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#!/usr/bin/env python
# -*- coding:utf-8 -*-
user,passwd = 'guo','123'
def auth(auth_type):
print("auth func:",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("User has passwd authentication")
re = func(*args,**kwargs)
print(re)
else:
exit("Invalid username or password")
if auth_type == "ldap":
print("I'm ldap")
func(*args, **kwargs)
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()
home()
bbs()