This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from collections import namedtuple | |
| User = namedtuple('User', field_names=['username', 'role']) | |
| current_user = User(username='Jeff', role='red') | |
| def role_required(required_role): | |
| def has_role(current_user): | |
| return current_user.role == required_role | |
| def role_decorator(func): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import contextlib | |
| import numpy as np | |
| # For info on contextlib, see https://docs.python.org/3/library/contextlib.html | |
| @contextlib.contextmanager | |
| def local_seed(seed): | |
| state = np.random.get_state() | |
| np.random.seed(seed) | |
| try: | |
| yield |