示例#1
0
 def visit_tryfinally(self, node, parent):
     """visit a TryFinally node by returning a fresh instance of it"""
     newnode = new.TryFinally()
     _lineno_parent(node, newnode, parent)
     newnode.body = [self.visit(child, newnode) for child in node.body]
     newnode.finalbody = [self.visit(n, newnode) for n in node.finalbody]
     return newnode
示例#2
0
 def visit_try(self, node, parent, assign_ctx=None):
     # python 3.3 introduce a new Try node replacing TryFinally/TryExcept nodes
     # pylint: disable=redefined-variable-type
     if node.finalbody:
         newnode = new.TryFinally()
         _lineno_parent(node, newnode, parent)
         newnode.finalbody = [self.visit(n, newnode, assign_ctx)
                              for n in node.finalbody]
         if node.handlers:
             excnode = new.TryExcept()
             _lineno_parent(node, excnode, newnode)
             excnode.body = [self.visit(child, excnode, assign_ctx)
                             for child in node.body]
             excnode.handlers = [self.visit(child, excnode, assign_ctx)
                                 for child in node.handlers]
             excnode.orelse = [self.visit(child, excnode, assign_ctx)
                               for child in node.orelse]
             newnode.body = [excnode]
         else:
             newnode.body = [self.visit(child, newnode, assign_ctx)
                             for child in node.body]
     elif node.handlers:
         newnode = new.TryExcept()
         _lineno_parent(node, newnode, parent)
         newnode.body = [self.visit(child, newnode, assign_ctx)
                         for child in node.body]
         newnode.handlers = [self.visit(child, newnode, assign_ctx)
                             for child in node.handlers]
         newnode.orelse = [self.visit(child, newnode, assign_ctx)
                           for child in node.orelse]
     return newnode
示例#3
0
 def visit_tryfinally(self, node, parent):
     """visit a TryFinally node by returning a fresh instance of it"""
     newnode = nodes.TryFinally(node.lineno, node.col_offset, parent)
     newnode.postinit(
         [self.visit(child, newnode) for child in node.body],
         [self.visit(n, newnode) for n in node.finalbody],
     )
     return newnode
示例#4
0
 def visit_tryfinally(self, node, parent):
     """visit a TryFinally node by returning a fresh instance of it"""
     newnode = nodes.TryFinally(node.lineno, node.col_offset, parent)
     body = nodes.Block(
         'body',
         [self.visit(n, newnode) for n in node.body],
         newnode)
     finalbody = nodes.Block(
         'finalbody',
         [self.visit(n, newnode) for n in node.finalbody],
         newnode)
     newnode.postinit(body, finalbody)
     return newnode
示例#5
0
 def visit_try(self, node, parent):
     # python 3.3 introduce a new Try node replacing
     # TryFinally/TryExcept nodes
     if node.finalbody:
         newnode = nodes.TryFinally(node.lineno, node.col_offset, parent)
         if node.handlers:
             body = [self.visit_tryexcept(node, newnode)]
         else:
             body = [self.visit(child, newnode) for child in node.body]
         newnode.postinit(body,
                          [self.visit(n, newnode) for n in node.finalbody])
         return newnode
     elif node.handlers:
         return self.visit_tryexcept(node, parent)
示例#6
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, newnode)
             excnode.body = [self.visit(child, excnode) for child in node.body]
             excnode.handlers = [self.visit(child, excnode) for child in node.handlers]
             excnode.orelse = [self.visit(child, excnode) 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]
     return newnode