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


Python codeop.PyCF_DONT_IMPLY_DEDENT方法代码示例

本文整理汇总了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) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:24,代码来源:test_codeop.py

示例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) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:24,代码来源:test_codeop.py

示例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) 
开发者ID:ofermend,项目名称:medicare-demo,代码行数:24,代码来源:test_codeop.py

示例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] 
开发者ID:vxgmichel,项目名称:aioconsole,代码行数:23,代码来源:execute.py

示例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() 
开发者ID:tulir,项目名称:mautrix-python,代码行数:7,代码来源:manhole.py


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