async def liteval(expr: str, verbose: Optional[bool] = False) -> int: """Evaluation of a Python literal.""" app = current_app() if verbose: app.io.info('Verbose mode is on!') app.io.raw(ast.literal_eval(expr)) return 0
async def handle_A_and_B(ecx): app = current_app() if isinstance(ecx, ExcA): app.bag.exc_list.append('A') elif isinstance(ecx, ExcB): app.bag.exc_list.append('B') else: assert False, 'this should not happen'
async def before_cd_hook_one(path: PagePath): self.assertIsInstance(path, PagePath) self.assertEqual(path, '/') current_app().bag.values.append(1)
async def after_not_real(): current_app().bag.after_hook_did_fire = True
async def before_not_real(): current_app().bag.before_hook_did_fire = True
async def catch_all_hook(exc): current_app().bag.lask_hook = 'D' self.assertIsInstance(exc, ExcD) self.assertEqual(exc.args[0], 'D')
def inc_prompt(): inner_app_ref = current_app() inner_app_ref.bag.counter += 1 return f'{inner_app_ref.bag.counter}> '
async def before_my_command(x: int): current_app().bag.before.append(x)
async def hook_A(exc): current_app().bag.last_hook = 'A' self.assertIsInstance(exc, ExcA) self.assertEqual(exc.args[0], 'A')
async def hook_ExcExit(exc: ExcExit): self.assertIsInstance(exc, ExcExit) current_app().bag.did_hook_on_exit = True
async def hook_exc_after(exc: ExcAfter): self.assertIsInstance(exc, ExcAfter) current_app().bag.did_hook_after = True
async def hook_exc_before(exc: ExcBefore): self.assertIsInstance(exc, ExcBefore) current_app().bag.did_hook_before = True
async def hook_exc_two(exc): app = current_app() app.bag.marker = 'two'
async def hook_exc_one(exc): app = current_app() app.bag.marker = 'one'
async def inc_counter(): inner_app_ref = current_app() inner_app_ref.bag.init_count += 1
async def after_cd_hook_two(path: PagePath): self.assertIsInstance(path, PagePath) self.assertEqual(path, '/') current_app().bag.values.append(4)
async def my_command(x: int): current_app().bag.values.append(x)
async def hook_B(exc): current_app().bag.last_hook = 'B' self.assertIsInstance(exc, ExcB) self.assertEqual(exc.args[0], 'B')
async def after_my_command(x: int): current_app().bag.after.append(x)
async def hook_C(exc): current_app().bag.last_hook = 'C' self.assertIsInstance(exc, ExcC) self.assertEqual(exc.args[0], 'C')