def _run_else_branch(self, data, failures, handler_error): else_error = None if data.else_branch: run = self._run and not failures and not handler_error result = TryBranchResult(data.ELSE) else_error = self._run_branch(data.else_branch, result, run) return else_error
def _run_finally_branch(self, data): if data.finally_branch: run = self._run and not data.error with StatusReporter(data.finally_branch, TryBranchResult(data.FINALLY), self._context, run): runner = BodyRunner(self._context, run, self._templated) runner.run(data.finally_branch.body)
def run(self, data): run = self._run with StatusReporter(data, TryResult(), self._context, run): if data.error: self._run_invalid(data) return False result = TryBranchResult(data.TRY) failures = self._run_branch(data.try_branch, result, run) self._run_handlers(data, failures) return run
def _run_invalid(self, data): error_reported = False for branch in data.body: result = TryBranchResult(branch.type, branch.patterns, branch.variable) with StatusReporter(branch, result, self._context, run=False, suppress=True): runner = BodyRunner(self._context, run=False, templated=self._templated) runner.run(branch.body) if not error_reported: error_reported = True raise ExecutionFailed(data.error) raise ExecutionFailed(data.error)
def _run_finally(self, data, run): if data.finally_branch: result = TryBranchResult(data.FINALLY) try: with StatusReporter(data.finally_branch, result, self._context, run): runner = BodyRunner(self._context, run, self._templated) runner.run(data.finally_branch.body) except ExecutionStatus as err: return err else: return None
def _run_excepts(self, data, error, run): for branch in data.except_branches: try: run_branch = run and self._should_run_except(branch, error) except DataError as err: run_branch = run = False error = ExecutionFailed(str(err)) result = TryBranchResult(branch.type, branch.patterns, branch.variable) if run_branch: if branch.variable: self._context.variables[branch.variable] = str(error) error = self._run_branch(branch, result, run=True) run = False else: self._run_branch(branch, result, run=False) return error
def _run_except_handlers(self, data, failures): handler_matched = False handler_error = None for handler in data.except_branches: run, handler_error = self._should_run_handler( data, failures, handler, handler_matched, handler_error) if run: handler_matched = True if handler.variable: self._context.variables[handler.variable] = str(failures) result = TryBranchResult(handler.type, handler.patterns, handler.variable) if not handler_error: handler_error = self._run_branch(handler, result, run) else: self._run_branch(handler, result, run) return handler_error, handler_matched
def _run_finally(self, data, run): if data.finally_branch: result = TryBranchResult(data.FINALLY) return self._run_branch(data.finally_branch, result, run)
def _run_else(self, data, run): if data.else_branch: result = TryBranchResult(data.ELSE) return self._run_branch(data.else_branch, result, run)
def _run_try(self, data, run): result = TryBranchResult(data.TRY) return self._run_branch(data.try_branch, result, run)