Python codeop.PyCF_DONT_IMPLY_DEDENT() Examples

The following are 12 code examples of codeop.PyCF_DONT_IMPLY_DEDENT(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module codeop , or try the search function .
Example #1
Source File: test_codeop.py    From ironpython2 with Apache License 2.0 6 votes vote down vote up
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) 
Example #2
Source File: test_codeop.py    From BinderFilter with MIT License 6 votes vote down vote up
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) 
Example #3
Source File: test_codeop.py    From oss-ftp with MIT License 6 votes vote down vote up
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) 
Example #4
Source File: test_codeop.py    From Fluid-Designer with GNU General Public License v3.0 6 votes vote down vote up
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) 
Example #5
Source File: test_codeop.py    From ironpython3 with Apache License 2.0 6 votes vote down vote up
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) 
Example #6
Source File: test_codeop.py    From gcblue with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
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) 
Example #7
Source File: test_codeop.py    From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 6 votes vote down vote up
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) 
Example #8
Source File: test_codeop.py    From medicare-demo with Apache License 2.0 6 votes vote down vote up
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) 
Example #9
Source File: test_codeop.py    From CTFCrackTools-V2 with GNU General Public License v3.0 6 votes vote down vote up
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) 
Example #10
Source File: execute.py    From aioconsole with GNU General Public License v3.0 6 votes vote down vote up
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] 
Example #11
Source File: test_codeop.py    From CTFCrackTools with GNU General Public License v3.0 6 votes vote down vote up
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) 
Example #12
Source File: manhole.py    From mautrix-python with Mozilla Public License 2.0 5 votes vote down vote up
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()