當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。