示例#1
0
文件: eval.py 项目: ntulip/tweetapp
    def visit_Subscript(self, node):
        if not isinstance(node.ctx, _ast.Load) or not isinstance(node.slice, _ast.Index):
            return ASTTransformer.visit_Subscript(self, node)

        func = _new(_ast.Name, "_lookup_item", _ast.Load())
        args = [self.visit(node.value), _new(_ast.Tuple, (self.visit(node.slice.value),), _ast.Load())]
        return _new(_ast.Call, func, args, [])
示例#2
0
    def visit_Attribute(self, node):
        if not isinstance(node.ctx, _ast.Load):
            return ASTTransformer.visit_Attribute(self, node)

        func = _new(_ast.Name, '_lookup_attr', _ast.Load())
        args = [self.visit(node.value), _new(_ast.Str, node.attr)]
        return _new(_ast.Call, func, args, [])
示例#3
0
文件: eval.py 项目: anandu/pylibs
    def visit_Attribute(self, node):
        if not isinstance(node.ctx, _ast.Load):
            return ASTTransformer.visit_Attribute(self, node)

        func = _new(_ast.Name, '_lookup_attr', _ast.Load())
        args = [self.visit(node.value), _new(_ast.Str, node.attr)]
        return _new(_ast.Call, func, args, [])
示例#4
0
 def visit_ClassDef(self, node):
     if len(self.locals) > 1:
         self.locals[-1].add(node.name)
     self.locals.append(set())
     try:
         return ASTTransformer.visit_ClassDef(self, node)
     finally:
         self.locals.pop()
示例#5
0
文件: eval.py 项目: anandu/pylibs
 def visit_ClassDef(self, node):
     if len(self.locals) > 1:
         self.locals[-1].add(node.name)
     self.locals.append(set())
     try:
         return ASTTransformer.visit_ClassDef(self, node)
     finally:
         self.locals.pop()
示例#6
0
    def visit_FunctionDef(self, node):
        if len(self.locals) > 1:
            self.locals[-1].add(node.name)

        self.locals.append(self._extract_names(node.args))
        try:
            return ASTTransformer.visit_FunctionDef(self, node)
        finally:
            self.locals.pop()
示例#7
0
文件: eval.py 项目: anandu/pylibs
    def visit_FunctionDef(self, node):
        if len(self.locals) > 1:
            self.locals[-1].add(node.name)

        self.locals.append(self._extract_names(node.args))
        try:
            return ASTTransformer.visit_FunctionDef(self, node)
        finally:
            self.locals.pop()
示例#8
0
    def visit_Subscript(self, node):
        if not isinstance(node.ctx, _ast.Load) or \
                not isinstance(node.slice, _ast.Index):
            return ASTTransformer.visit_Subscript(self, node)

        func = _new(_ast.Name, '_lookup_item', _ast.Load())
        args = [
            self.visit(node.value),
            _new(_ast.Tuple, (self.visit(node.slice.value), ), _ast.Load())
        ]
        return _new(_ast.Call, func, args, [])
示例#9
0
 def visit_ImportFrom(self, node):
     if [a.name for a in node.names] == ['*']:
         if has_star_import_bug:
             # This is a Python 2.4 bug. Only if we have a broken Python
             # version do we need to apply this hack
             node = _new(_ast.Expr, _new(_ast.Call,
                 _new(_ast.Name, '_star_import_patch'), [
                     _new(_ast.Name, '__data__'),
                     _new(_ast.Str, node.module)
                 ], (), ()))
         return node
     if len(self.locals) > 1:
         self.locals[-1].update(self._extract_names(node))
     return ASTTransformer.visit_ImportFrom(self, node)
示例#10
0
    def visit_Subscript(self, node):
        if not isinstance(node.ctx, _ast.Load) or \
                not isinstance(node.slice, (_ast.Index, _ast_Constant, _ast.Name, _ast.Call)):
            return ASTTransformer.visit_Subscript(self, node)

        # Before Python 3.9 "foo[key]" wrapped the load of "key" in
        # "ast.Index(ast.Name(...))"
        if isinstance(node.slice, (_ast.Name, _ast.Call)):
            slice_value = node.slice
        else:
            slice_value = node.slice.value

        func = _new(_ast.Name, '_lookup_item', _ast.Load())
        args = [
            self.visit(node.value),
            _new(_ast.Tuple, (self.visit(slice_value), ), _ast.Load())
        ]
        return _new(_ast.Call, func, args, [])
示例#11
0
 def visit_ImportFrom(self, node):
     if [a.name for a in node.names] == ['*']:
         return node
     if len(self.locals) > 1:
         self.locals[-1].update(self._extract_names(node))
     return ASTTransformer.visit_ImportFrom(self, node)
示例#12
0
 def visit_For(self, node):
     self.locals.append(set())
     try:
         return ASTTransformer.visit_For(self, node)
     finally:
         self.locals.pop()
示例#13
0
 def visit_Lambda(self, node):
     self.locals.append(self._extract_names(node.args))
     try:
         return ASTTransformer.visit_Lambda(self, node)
     finally:
         self.locals.pop()
示例#14
0
文件: eval.py 项目: ntulip/tweetapp
 def visit_For(self, node):
     self.locals.append(set())
     try:
         return ASTTransformer.visit_For(self, node)
     finally:
         self.locals.pop()
示例#15
0
 def visit_Import(self, node):
     if len(self.locals) > 1:
         self.locals[-1].update(self._extract_names(node))
     return ASTTransformer.visit_Import(self, node)
示例#16
0
文件: eval.py 项目: anandu/pylibs
 def visit_Import(self, node):
     if len(self.locals) > 1:
         self.locals[-1].update(self._extract_names(node))
     return ASTTransformer.visit_Import(self, node)
示例#17
0
文件: eval.py 项目: anandu/pylibs
 def visit_Lambda(self, node):
     self.locals.append(self._extract_names(node.args))
     try:
         return ASTTransformer.visit_Lambda(self, node)
     finally:
         self.locals.pop()