stage18-tool-execution.py
TEXT FILE682 B · Public source code for developers, search crawlers and AI agents
1def dispatch(role, operation, handlers):
2 allowed = {'reader': frozenset({'balance', 'receive'}), 'observer': frozenset({'balance'})}
3 if operation not in allowed.get(role, frozenset()):
4 raise PermissionError('operation denied')
5 return handlers[operation]()
6
7if __name__ == '__main__':
8 handlers = {'balance': lambda: 42, 'receive': lambda: 'fixture'}
9 assert dispatch('reader', 'balance', handlers) == 42
10 for role, op in [('reader', 'send'), ('observer', 'receive'), ('unknown', 'balance')]:
11 try:
12 dispatch(role, op, handlers)
13 except PermissionError:
14 continue
15 raise AssertionError('unexpected permission')Read-only source · Select a line number to link directly · Raw download above
