示例#1
0
        def wrapExpressionBuiltinExecfileCreation(filename, globals, locals,
                                                  source_ref):
            provider = node.getParentVariableProvider()

            # TODO: Can't really be true, can it?
            if provider.isExpressionFunctionBody():
                provider.markAsExecContaining()

                if provider.isClassDictCreation():
                    provider.markAsUnqualifiedExecContaining(source_ref)

            globals_wrap, locals_wrap = wrapEvalGlobalsAndLocals(
                provider=provider,
                globals_node=globals,
                locals_node=locals,
                exec_mode=False,
                source_ref=source_ref)

            return ExpressionBuiltinExecfile(source_code=ExpressionCallEmpty(
                called=ExpressionAttributeLookup(
                    expression=ExpressionBuiltinOpen(
                        filename=filename,
                        mode=ExpressionConstantRef(constant="rU",
                                                   source_ref=source_ref),
                        buffering=None,
                        source_ref=source_ref),
                    attribute_name="read",
                    source_ref=source_ref),
                source_ref=source_ref),
                                             globals_arg=globals_wrap,
                                             locals_arg=locals_wrap,
                                             source_ref=source_ref)
示例#2
0
        def wrapExpressionBuiltinExecfileCreation(filename, globals_arg,
                                                  locals_arg, source_ref):
            outline_body = ExpressionOutlineBody(
                provider   = node.getParentVariableProvider(),
                name       = "execfile_call",
                source_ref = source_ref
            )

            globals_ref, locals_ref, tried, final = wrapEvalGlobalsAndLocals(
                provider     = node.getParentVariableProvider(),
                globals_node = globals_arg,
                locals_node  = locals_arg,
                temp_scope   = outline_body.getOutlineTempScope(),
                source_ref   = source_ref
            )

            tried = makeStatementsSequence(
                statements = (
                    tried,
                    StatementReturn(
                        expression = ExpressionBuiltinExecfile(
                            source_code = ExpressionCallEmpty(
                                called     = ExpressionAttributeLookup(
                                    source         = ExpressionBuiltinOpen(
                                        filename   = filename,
                                        mode       = ExpressionConstantRef(
                                            constant   = "rU",
                                            source_ref = source_ref
                                        ),
                                        buffering  = None,
                                        source_ref = source_ref
                                    ),
                                    attribute_name = "read",
                                    source_ref     = source_ref
                                ),
                                source_ref = source_ref
                            ),
                            globals_arg = globals_ref,
                            locals_arg  = locals_ref,
                            source_ref  = source_ref
                        ),
                        source_ref = source_ref
                    )
                ),
                allow_none = False,
                source_ref = source_ref
            )

            outline_body.setBody(
                makeStatementsSequenceFromStatement(
                    statement = makeTryFinallyStatement(
                        provider   = outline_body,
                        tried      = tried,
                        final      = final,
                        source_ref = source_ref
                    )
                )
            )

            return outline_body
        def wrapExpressionBuiltinExecfileCreation(filename, globals_arg,
                                                  locals_arg, source_ref):
            provider = node.getParentVariableProvider()

            temp_scope = provider.allocateTempScope("execfile")

            globals_ref, locals_ref, tried, final = wrapEvalGlobalsAndLocals(
                provider=provider,
                globals_node=globals_arg,
                locals_node=locals_arg,
                temp_scope=temp_scope,
                source_ref=source_ref)

            return ExpressionTryFinally(
                tried=tried,
                final=final,
                expression=ExpressionBuiltinExecfile(
                    source_code=ExpressionCallEmpty(
                        called=ExpressionAttributeLookup(
                            source=ExpressionBuiltinOpen(
                                filename=filename,
                                mode=ExpressionConstantRef(
                                    constant="rU", source_ref=source_ref),
                                buffering=None,
                                source_ref=source_ref),
                            attribute_name="read",
                            source_ref=source_ref),
                        source_ref=source_ref),
                    globals_arg=globals_ref,
                    locals_arg=locals_ref,
                    source_ref=source_ref),
                source_ref=source_ref)
示例#4
0
        def wrapExpressionBuiltinExecfileCreation(filename, globals_arg,
                                                  locals_arg, source_ref):

            provider = node.getParentVariableProvider()

            if provider.isExpressionFunctionBody():
                provider.markAsExecContaining()

            return ExpressionBuiltinExecfile(source_code=ExpressionCallEmpty(
                called=ExpressionAttributeLookup(
                    expression=ExpressionBuiltinOpen(
                        filename=filename,
                        mode=ExpressionConstantRef(constant="rU",
                                                   source_ref=source_ref),
                        buffering=None,
                        source_ref=source_ref),
                    attribute_name="read",
                    source_ref=source_ref),
                source_ref=source_ref),
                                             globals_arg=globals_arg,
                                             locals_arg=locals_arg,
                                             source_ref=source_ref)