def wrap_with_try(self, node):
        """Wrap an ast node in a 'try' node to enter debug on exception."""
        handlers = []

        if self.ignore_exceptions is None:
            handlers.append(ast.ExceptHandler(type=None,
                                              name=None,
                                              body=[ast.Raise()]))

        else:
            ignores_nodes = self.ignore_exceptions

            handlers.append(ast.ExceptHandler(type=ast.Tuple(ignores_nodes,
                                                             ast.Load()),
                                              name=None,
                                              body=[ast.Raise()]))

            if self.catch_exception is None or \
                    get_node_value(self.catch_exception) not in \
                    (get_node_value(ast_node)
                     for ast_node in self.ignore_exceptions):

                call_extra_parameters = [] if IS_PYTHON_3 else [None, None]
                start_debug_cmd = ast.Expr(
                    value=ast.Call(ast.Name("start_debugging", ast.Load()),
                                   [], [], *call_extra_parameters))

                catch_exception_type = None
                if self.catch_exception is not None:
                    catch_exception_type = self.catch_exception

                handlers.append(ast.ExceptHandler(type=catch_exception_type,
                                                  name=None,
                                                  body=[start_debug_cmd]))

        try_except_extra_params = {"finalbody": []} if IS_PYTHON_3 else {}

        new_node = self.ast_try_except(orelse=[], body=[node],
                                       handlers=handlers,
                                       **try_except_extra_params)

        return ast.copy_location(new_node, node)
def wrap_with_try ( self , node ) : handlers = [ ] if self . ignore_exceptions is None : handlers . append ( ast . ExceptHandler ( type = None , name = None , body = [ ast . Raise ( ) ] ) ) else : ignores_nodes = self . ignore_exceptions handlers . append ( ast . ExceptHandler ( type = ast . Tuple ( ignores_nodes , ast . Load ( ) ) , name = None , body = [ ast . Raise ( ) ] ) ) if self . catch_exception is None or get_node_value ( self . catch_exception ) not in ( get_node_value ( ast_node ) for ast_node in self . ignore_exceptions ) : call_extra_parameters = [ ] if IS_PYTHON_3 else [ None , None ] start_debug_cmd = ast . Expr ( value = ast . Call ( ast . Name ( "start_debugging" , ast . Load ( ) ) , [ ] , [ ] , * call_extra_parameters ) ) catch_exception_type = None if self . catch_exception is not None : catch_exception_type = self . catch_exception handlers . append ( ast . ExceptHandler ( type = catch_exception_type , name = None , body = [ start_debug_cmd ] ) ) try_except_extra_params = { "finalbody" : [ ] } if IS_PYTHON_3 else { } new_node = self . ast_try_except ( orelse = [ ] , body = [ node ] , handlers = handlers , ** try_except_extra_params ) return ast . copy_location ( new_node , node )
Wrap an ast node in a 'try' node to enter debug on exception.