コード例 #1
0
 def visit_tryexcept(self, node, parent):
     """visit a TryExcept node by returning a fresh instance of it"""
     newnode = new.TryExcept()
     _lineno_parent(node, newnode, parent)
     newnode.body = [self.visit(child, newnode) for child in node.body]
     newnode.handlers = [self.visit(child, newnode) for child in node.handlers]
     newnode.orelse = [self.visit(child, newnode) for child in node.orelse]
     newnode.set_line_info(newnode.last_child())
     return newnode
コード例 #2
0
 def visit_tryexcept(self, node, parent):
     """visit a TryExcept node by returning a fresh instance of it"""
     newnode = new.TryExcept()
     self._set_infos(node, newnode, parent)
     newnode.body = [self.visit(child, newnode) for child in node.body.nodes]
     newnode.handlers = [self._visit_excepthandler(newnode, values)
                         for values in node.handlers]
     newnode.orelse = self._init_else_node(node, newnode)
     return newnode
コード例 #3
0
 def visit_try(self, node, parent):
     # python 3.3 introduce a new Try node replacing TryFinally/TryExcept nodes
     if node.finalbody:
         newnode = new.TryFinally()
         _lineno_parent(node, newnode, parent)
         newnode.finalbody = [self.visit(n, newnode) for n in node.finalbody]
         if node.handlers:
             excnode = new.TryExcept()
             _lineno_parent(node, excnode, parent)
             excnode.body = [self.visit(child, newnode) for child in node.body]
             excnode.handlers = [self.visit(child, newnode) for child in node.handlers]
             excnode.orelse = [self.visit(child, newnode) for child in node.orelse]
             newnode.body = [excnode]
         else:
             newnode.body = [self.visit(child, newnode) for child in node.body]
     elif node.handlers:
         newnode = new.TryExcept()
         _lineno_parent(node, newnode, parent)
         newnode.body = [self.visit(child, newnode) for child in node.body]
         newnode.handlers = [self.visit(child, newnode) for child in node.handlers]
         newnode.orelse = [self.visit(child, newnode) for child in node.orelse]
     newnode.set_line_info(newnode.last_child())
     return newnode