コード例 #1
0
ファイル: eval.py プロジェクト: alon/polinax
 def visitName(self, node):
     # If the name refers to a local inside a lambda, list comprehension, or
     # generator expression, leave it alone
     if node.name not in flatten(self.locals):
         # Otherwise, translate the name ref into a context lookup
         func_args = [ast.Name('__data__'), ast.Const(node.name)]
         node = ast.CallFunc(ast.Name('_lookup_name'), func_args)
     return node
コード例 #2
0
ファイル: eval.py プロジェクト: ntulip/tweetapp
    def visit_Name(self, node):
        # If the name refers to a local inside a lambda, list comprehension, or
        # generator expression, leave it alone
        if isinstance(node.ctx, _ast.Load) and node.id not in flatten(self.locals):
            # Otherwise, translate the name ref into a context lookup
            name = _new(_ast.Name, "_lookup_name", _ast.Load())
            namearg = _new(_ast.Name, "__data__", _ast.Load())
            strarg = _new(_ast.Str, node.id)
            node = _new(_ast.Call, name, [namearg, strarg], [])
        elif isinstance(node.ctx, _ast.Store):
            if len(self.locals) > 1:
                self.locals[-1].add(node.id)

        return node
コード例 #3
0
    def visit_Name(self, node):
        # If the name refers to a local inside a lambda, list comprehension, or
        # generator expression, leave it alone
        if isinstance(node.ctx, _ast.Load) and \
                node.id not in flatten(self.locals):
            # Otherwise, translate the name ref into a context lookup
            name = _new(_ast.Name, '_lookup_name', _ast.Load())
            namearg = _new(_ast.Name, '__data__', _ast.Load())
            strarg = _new(_ast.Str, node.id)
            node = _new(_ast.Call, name, [namearg, strarg], [])
        elif isinstance(node.ctx, _ast.Store):
            if len(self.locals) > 1:
                self.locals[-1].add(node.id)

        return node
コード例 #4
0
ファイル: eval.py プロジェクト: alon/polinax
 def visitAugAssign(self, node):
     if isinstance(node.node, ast.Name) \
             and node.node.name not in flatten(self.locals):
         name = node.node.name
         node.node = ast.Subscript(ast.Name('__data__'), 'OP_APPLY',
                                   [ast.Const(name)])
         node.expr = self.visit(node.expr)
         return ast.If([
             (ast.Compare(ast.Const(name), [('in', ast.Name('__data__'))]),
              ast.Stmt([node]))],
             ast.Stmt([ast.Raise(ast.CallFunc(ast.Name('UndefinedError'),
                                              [ast.Const(name)]),
                                 None, None)]))
     else:
         return ASTTransformer.visitAugAssign(self, node)
コード例 #5
0
ファイル: eval.py プロジェクト: alon/polinax
 def visitLambda(self, node):
     self.locals.append(set(flatten(node.argnames)))
     try:
         return ASTTransformer.visitLambda(self, node)
     finally:
         self.locals.pop()
コード例 #6
0
ファイル: eval.py プロジェクト: jacoco/www.eclemma.org
 def visitLambda(self, node):
     self.locals.append(set(flatten(node.argnames)))
     node = ASTTransformer.visitLambda(self, node)
     self.locals.pop()
     return node