当前位置: 首页>>代码示例>>Python>>正文


Python ast.Stmt方法代码示例

本文整理汇总了Python中compiler.ast.Stmt方法的典型用法代码示例。如果您正苦于以下问题:Python ast.Stmt方法的具体用法?Python ast.Stmt怎么用?Python ast.Stmt使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在compiler.ast的用法示例。


在下文中一共展示了ast.Stmt方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: run

# 需要导入模块: from compiler import ast [as 别名]
# 或者: from compiler.ast import Stmt [as 别名]
def run(self, frame):
        expr = Interpretable(self.expr)
        expr.eval(frame)
        self.result = expr.result
        self.explanation = '... = ' + expr.explanation
        # fall-back-run the rest of the assignment
        ass = ast.Assign(self.nodes, ast.Name('__exprinfo_expr'))
        mod = ast.Module(None, ast.Stmt([ass]))
        mod.filename = '<run>'
        co = pycodegen.ModuleCodeGenerator(mod).getCode()
        try:
            frame.exec_(co, __exprinfo_expr=expr.result)
        except passthroughex:
            raise
        except:
            raise Failure(self) 
开发者ID:pytest-dev,项目名称:py,代码行数:18,代码来源:_assertionold.py

示例2: testMultipleLHS

# 需要导入模块: from compiler import ast [as 别名]
# 或者: from compiler.ast import Stmt [as 别名]
def testMultipleLHS(self):
        """ Test multiple targets on the left hand side. """

        snippets = ['a, b = 1, 2',
                    '(a, b) = 1, 2',
                    '((a, b), c) = (1, 2), 3']

        for s in snippets:
            a = transformer.parse(s)
            self.assertIsInstance(a, ast.Module)
            child1 = a.getChildNodes()[0]
            self.assertIsInstance(child1, ast.Stmt)
            child2 = child1.getChildNodes()[0]
            self.assertIsInstance(child2, ast.Assign)

            # This actually tests the compiler, but it's a way to assure the ast
            # is correct
            c = compile(s, '<string>', 'single')
            vals = {}
            exec c in vals
            assert vals['a'] == 1
            assert vals['b'] == 2 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:24,代码来源:test_transformer.py

示例3: CheckedEval

# 需要导入模块: from compiler import ast [as 别名]
# 或者: from compiler.ast import Stmt [as 别名]
def CheckedEval(file_contents):
  """Return the eval of a gyp file.

  The gyp file is restricted to dictionaries and lists only, and
  repeated keys are not allowed.

  Note that this is slower than eval() is.
  """

  ast = compiler.parse(file_contents)
  assert isinstance(ast, Module)
  c1 = ast.getChildren()
  assert c1[0] is None
  assert isinstance(c1[1], Stmt)
  c2 = c1[1].getChildren()
  assert isinstance(c2[0], Discard)
  c3 = c2[0].getChildren()
  assert len(c3) == 1
  return CheckNode(c3[0], []) 
开发者ID:zhaoolee,项目名称:StarsAndClown,代码行数:21,代码来源:input.py

示例4: testMultipleLHS

# 需要导入模块: from compiler import ast [as 别名]
# 或者: from compiler.ast import Stmt [as 别名]
def testMultipleLHS(self):
        """ Test multiple targets on the left hand side. """

        snippets = ['a, b = 1, 2',
                    '(a, b) = 1, 2',
                    '((a, b), c) = (1, 2), 3']

        for s in snippets:
            a = transformer.parse(s)
            assert isinstance(a, ast.Module)
            child1 = a.getChildNodes()[0]
            assert isinstance(child1, ast.Stmt)
            child2 = child1.getChildNodes()[0]
            assert isinstance(child2, ast.Assign)

            # This actually tests the compiler, but it's a way to assure the ast
            # is correct
            c = compile(s, '<string>', 'single')
            vals = {}
            exec c in vals
            assert vals['a'] == 1
            assert vals['b'] == 2 
开发者ID:ofermend,项目名称:medicare-demo,代码行数:24,代码来源:test_transformer.py

示例5: _if_test

# 需要导入模块: from compiler import ast [as 别名]
# 或者: from compiler.ast import Stmt [as 别名]
def _if_test(self, keyword, test, consequence, current_klass):
        if test:
            expr = self.expr(test, current_klass)

            self.printo("    " + keyword + " (pyjslib.bool(" + expr + ")) {")
        else:
            self.printo("    " + keyword + " {")

        if isinstance(consequence, ast.Stmt):
            for child in consequence.nodes:
                self._stmt(child, current_klass)
        else:
            raise TranslationError("unsupported type (in _if_test)", consequence)

        self.printo("    }") 
开发者ID:thiagoralves,项目名称:OpenPLC_Editor,代码行数:17,代码来源:pyjs.py

示例6: _while

# 需要导入模块: from compiler import ast [as 别名]
# 或者: from compiler.ast import Stmt [as 别名]
def _while(self, node, current_klass):
        test = self.expr(node.test, current_klass)
        self.printo("    while (pyjslib.bool(" + test + ")) {")
        if isinstance(node.body, ast.Stmt):
            for child in node.body.nodes:
                self._stmt(child, current_klass)
        else:
            raise TranslationError("unsupported type (in _while)", node.body)
        self.printo("    }") 
开发者ID:thiagoralves,项目名称:OpenPLC_Editor,代码行数:11,代码来源:pyjs.py


注:本文中的compiler.ast.Stmt方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。