本文整理匯總了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()