本文整理汇总了Python中codeop.PyCF_DONT_IMPLY_DEDENT方法的典型用法代码示例。如果您正苦于以下问题:Python codeop.PyCF_DONT_IMPLY_DEDENT方法的具体用法?Python codeop.PyCF_DONT_IMPLY_DEDENT怎么用?Python codeop.PyCF_DONT_IMPLY_DEDENT使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类codeop
的用法示例。
在下文中一共展示了codeop.PyCF_DONT_IMPLY_DEDENT方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: assertValid
# 需要导入模块: import codeop [as 别名]
# 或者: from codeop import PyCF_DONT_IMPLY_DEDENT [as 别名]
def assertValid(self, str, symbol='single'):
'''succeed iff str is a valid piece of code'''
if is_jython:
code = compile_command(str, "<input>", symbol)
self.assertTrue(code)
if symbol == "single":
d,r = {},{}
saved_stdout = sys.stdout
sys.stdout = cStringIO.StringIO()
try:
exec code in d
exec compile(str,"<input>","single") in r
finally:
sys.stdout = saved_stdout
elif symbol == 'eval':
ctx = {'a': 2}
d = { 'value': eval(code,ctx) }
r = { 'value': eval(str,ctx) }
self.assertEqual(unify_callables(r),unify_callables(d))
else:
expected = compile(str, "<input>", symbol, PyCF_DONT_IMPLY_DEDENT)
self.assertEqual(compile_command(str, "<input>", symbol), expected)
示例2: assertValid
# 需要导入模块: import codeop [as 别名]
# 或者: from codeop import PyCF_DONT_IMPLY_DEDENT [as 别名]
def assertValid(self, str, symbol='single'):
'''succeed iff str is a valid piece of code'''
if is_jython:
code = compile_command(str, "<input>", symbol)
self.assertTrue(code)
if symbol == "single":
d,r = {},{}
saved_stdout = sys.stdout
sys.stdout = io.StringIO()
try:
exec(code, d)
exec(compile(str,"<input>","single"), r)
finally:
sys.stdout = saved_stdout
elif symbol == 'eval':
ctx = {'a': 2}
d = { 'value': eval(code,ctx) }
r = { 'value': eval(str,ctx) }
self.assertEqual(unify_callables(r),unify_callables(d))
else:
expected = compile(str, "<input>", symbol, PyCF_DONT_IMPLY_DEDENT)
self.assertEqual(compile_command(str, "<input>", symbol), expected)
示例3: assertValid
# 需要导入模块: import codeop [as 别名]
# 或者: from codeop import PyCF_DONT_IMPLY_DEDENT [as 别名]
def assertValid(self, str, symbol='single'):
'''succeed iff str is a valid piece of code'''
if is_jython:
code = compile_command(str, "<input>", symbol)
self.assertTrue(code)
if symbol == "single":
d,r = {},{}
saved_stdout = sys.stdout
sys.stdout = cStringIO.StringIO()
try:
exec code in d
exec compile(str,"<input>","single") in r
finally:
sys.stdout = saved_stdout
elif symbol == 'eval':
ctx = {'a': 2}
d = { 'value': eval(code,ctx) }
r = { 'value': eval(str,ctx) }
self.assertEquals(unify_callables(r),unify_callables(d))
else:
expected = compile(str, "<input>", symbol, PyCF_DONT_IMPLY_DEDENT)
self.assertEquals( compile_command(str, "<input>", symbol), expected)
示例4: compile_for_aexec
# 需要导入模块: import codeop [as 别名]
# 或者: from codeop import PyCF_DONT_IMPLY_DEDENT [as 别名]
def compile_for_aexec(
source, filename="<aexec>", mode="single", dont_imply_dedent=False, local={}
):
"""Return a list of (coroutine object, abstract base tree)."""
flags = ast.PyCF_ONLY_AST
if dont_imply_dedent:
flags |= codeop.PyCF_DONT_IMPLY_DEDENT
# Avoid a syntax error by wrapping code with `async def`
indented = "\n".join(line and " " * 4 + line for line in source.split("\n"))
coroutine = CORO_DEF + "\n" + indented + "\n"
interactive = compile(coroutine, filename, mode, flags).body[0]
# Check EOF errors
try:
compile(source, filename, mode, flags)
except SyntaxError as exc:
if exc.msg == "unexpected EOF while parsing":
raise
return [make_tree(statement, filename, mode) for statement in interactive.body]
示例5: __init__
# 需要导入模块: import codeop [as 别名]
# 或者: from codeop import PyCF_DONT_IMPLY_DEDENT [as 别名]
def __init__(self) -> None:
super().__init__()
self.compiler = functools.partial(compile, optimize=1,
flags=ast.PyCF_ONLY_AST | codeop.PyCF_DONT_IMPLY_DEDENT)
self.buf = BytesIO()