-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbite_12.py
More file actions
37 lines (25 loc) · 855 Bytes
/
bite_12.py
File metadata and controls
37 lines (25 loc) · 855 Bytes
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
# Online Python - IDE, Editor, Compiler, Interpreter
from collections import namedtuple
User = namedtuple('User', 'name role expired')
USER, ADMIN = 'user', 'admin'
SECRET = 'I am a very secret token'
julian = User(name='Julian', role=USER, expired=False)
bob = User(name='Bob', role=USER, expired=True)
pybites = User(name='PyBites', role=ADMIN, expired=False)
USERS = (julian, bob, pybites)
# define exception classes here
class UserDoesNotExist(Exception):
pass
class UserAccessExpired(Exception):
pass
class UserNoPermission(Exception):
pass
def get_secret_token(username):
for user in USERS:
if username == user.name:
if user.expired:
raise UserAccessExpired
if user.role != ADMIN:
raise UserNoPermission
return SECRET
raise UserDoesNotExist