本文整理汇总了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)
示例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
示例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], [])
示例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
示例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(" }")
示例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(" }")