Ejemplo n.º 1
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=makeCallNode(
                                ExpressionAttributeLookup(
                                    source=ExpressionBuiltinOpen(
                                        filename=filename,
                                        mode=makeConstantRefNode(
                                            constant="rU", source_ref=source_ref
                                        ),
                                        buffering=None,
                                        source_ref=source_ref,
                                    ),
                                    attribute_name="read",
                                    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
Ejemplo n.º 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=makeCallNode(
                                ExpressionAttributeLookup(
                                    expression=ExpressionBuiltinOpen(
                                        filename=filename,
                                        mode=makeConstantRefNode(
                                            constant="rU", source_ref=source_ref
                                        ),
                                        buffering=None,
                                        source_ref=source_ref,
                                    ),
                                    attribute_name="read",
                                    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
Ejemplo n.º 3
0
    def buildDirEmptyCase(source_ref):
        source = makeExpressionBuiltinLocals(
            provider=node.getParentVariableProvider(), source_ref=source_ref)

        result = makeCallNode(
            ExpressionAttributeLookup(source=source,
                                      attribute_name="keys",
                                      source_ref=source_ref), source_ref)

        # For Python3, keys doesn't really return values, but instead a handle
        # only, but we want it to be a list.
        if python_version >= 300:
            result = ExpressionBuiltinList(value=result, source_ref=source_ref)

        return result
Ejemplo n.º 4
0
    def buildDirEmptyCase(source_ref):
        source = makeExpressionBuiltinLocals(
            provider=node.getParentVariableProvider(), source_ref=source_ref
        )

        result = makeCallNode(
            ExpressionAttributeLookup(
                source=source, attribute_name="keys", source_ref=source_ref
            ),
            source_ref,
        )

        # For Python3, keys doesn't really return values, but instead a handle
        # only, but we want it to be a list.
        if python_version >= 300:
            result = ExpressionBuiltinList(value=result, source_ref=source_ref)

        return result
Ejemplo n.º 5
0
    def buildDirEmptyCase(source_ref):
        source = makeExpressionBuiltinLocals(
            locals_scope=locals_scope, source_ref=source_ref
        )

        result = makeCallNode(
            ExpressionAttributeLookup(
                expression=source, attribute_name="keys", source_ref=source_ref
            ),
            source_ref,
        )

        # For Python3, keys doesn't really return values, but instead a handle
        # only, but we want it to be a list.
        if python_version >= 300:
            result = ExpressionBuiltinList(value=result, source_ref=source_ref)

        return result