Ejemplo n.º 1
0
    def generic_visit(self, node):
        if node is None:
            return node
        if isinstance(node, (str)):
            import pdb
            pdb.set_trace()
            return node

#        if not isinstance(node, (_ast.expr, _ast.expr_context, _ast.slice, _ast.operator, _ast.boolop)):
#            raise Exception("expected a Python '_ast.expr' node (got %r)" % (type(node),))
        return NodeTransformer.generic_visit(self, node)
Ejemplo n.º 2
0
 def generic_visit(self, node):
     name = 'do{}'.format(type(node).__name__)
     node = NodeTransformer.generic_visit(self, node)
     if hasattr(self, name):
         boundary, value = getattr(self, name)(node)
         newstr = boundary
         for char in value:
             newstr += MAPPING[CHAR_MAPPING[char]]['unicode']
         newstr += boundary
         return copy_location(Name(id=newstr), node)
     return node
Ejemplo n.º 3
0
    def generic_visit(self, node):
        """
        visits the `AST`, if it's the right one, replace it

        :param node: The AST node
        :type node: ```AST```

        :return: Potentially changed AST node
        :rtype: ```AST```
        """
        if (
            not self.replaced
            and hasattr(node, "_location")
            and node._location == self.search
        ):
            self.replaced = True
            return self.replacement_node
        else:
            return NodeTransformer.generic_visit(self, node)
Ejemplo n.º 4
0
 def generic_visit(self, node):
     if (isinstance(node, ast.stmt)
             and self.references_arg(node)) or isinstance(node, ast.Return):
         return self.get_waits() + [node]
     return NodeTransformer.generic_visit(self, node)
Ejemplo n.º 5
0
 def generic_visit(self, node):
     if not isinstance(node, CtreeNode):
         NodeTransformer.generic_visit(self,node)
         return NonCtreeNode(node)
     return NodeTransformer.generic_visit(self,node)
Ejemplo n.º 6
0
 def visit_Return(self, node):
     return NodeTransformer.generic_visit(self, node.value)