#NEWLINE# def _buildWithNode( provider , context_expr , assign_target , body , body_lineno , sync , source_ref ) : #NEWLINE# #INDENT# with_source = buildNode ( provider , context_expr , source_ref ) #NEWLINE# if Options . isFullCompat ( ) : #NEWLINE# #INDENT# source_ref = with_source . getCompatibleSourceReference ( ) #NEWLINE# #UNINDENT# temp_scope = provider . allocateTempScope ( 'with' ) #NEWLINE# tmp_source_variable = provider . allocateTempVariable ( temp_scope = context_expr , name = 'source' ) #NEWLINE# tmp_exit_variable = provider . allocateTempVariable ( temp_scope = temp_scope , name = 'exit' ) #NEWLINE# tmp_enter_variable = provider . allocateTempVariable ( temp_scope = temp_scope , name = 'enter' ) #NEWLINE# tmp_indicator_variable = provider . allocateTempVariable ( temp_scope = temp_scope , name = 'indicator' ) #NEWLINE# statements = ( buildAssignmentStatements ( provider = provider , node = assign_target , allow_none = True , source = ExpressionTempVariableRef ( variable = tmp_enter_variable , source_ref = source_ref ) , source_ref = source_ref ) , body ) #NEWLINE# with_body = makeStatementsSequence ( statements = statements , allow_none = True , source_ref = source_ref ) #NEWLINE# if Options . isFullCompat ( ) : #NEWLINE# #INDENT# if body : #NEWLINE# #INDENT# deepest = body #NEWLINE# while deepest . getVisitableNodes ( ) : #NEWLINE# #INDENT# deepest = deepest . getVisitableNodes ( ) [ ( - 1 ) ] #NEWLINE# #UNINDENT# body_lineno = deepest . getCompatibleSourceReference ( ) . getLineNumber ( ) #NEWLINE# #UNINDENT# with_exit_source_ref = source_ref . atLineNumber ( body_lineno ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# with_exit_source_ref = source_ref #NEWLINE# #UNINDENT# if ( python_version < 270 ) : #NEWLINE# #INDENT# attribute_lookup_class = ExpressionAttributeLookup #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# attribute_lookup_class = ExpressionAttributeLookupSpecial #NEWLINE# #UNINDENT# enter_value = ExpressionCallEmpty ( called = attribute_lookup_class ( source = ExpressionTempVariableRef ( variable = tmp_source_variable , source_ref = source_ref ) , attribute_name = ( '__enter__' if sync else '__aenter__' ) , source_ref = source_ref ) , source_ref = source_ref ) #NEWLINE# exit_value_exception = ExpressionCallNoKeywords ( called = ExpressionTempVariableRef ( variable = tmp_exit_variable , source_ref = with_exit_source_ref ) , args = ExpressionMakeTuple ( elements = ( ExpressionCaughtExceptionTypeRef ( source_ref = with_exit_source_ref ) , ExpressionCaughtExceptionValueRef ( source_ref = with_exit_source_ref ) , ExpressionCaughtExceptionTracebackRef ( source_ref = source_ref ) ) , source_ref = source_ref ) , source_ref = with_exit_source_ref ) #NEWLINE# exit_value_no_exception = ExpressionCallNoKeywords ( called = ExpressionTempVariableRef ( variable = tmp_exit_variable , source_ref = source_ref ) , args = ExpressionConstantRef ( constant = ( None , None , None ) , source_ref = source_ref ) , source_ref = with_exit_source_ref ) #NEWLINE# if ( not sync ) : #NEWLINE# #INDENT# enter_value = ExpressionAsyncWait ( expression = enter_value , source_ref = source_ref ) #NEWLINE# exit_value_exception = ExpressionAsyncWait ( expression = exit_value_exception , source_ref = source_ref ) #NEWLINE# exit_value_no_exception = ExpressionAsyncWait ( expression = exit_value_no_exception , source_ref = source_ref ) #NEWLINE# #UNINDENT# statements = [ StatementAssignmentVariable ( variable_ref = ExpressionTargetTempVariableRef ( variable = tmp_source_variable , source_ref = source_ref ) , source = with_source , source_ref = source_ref ) , StatementAssignmentVariable ( variable_ref = ExpressionTargetTempVariableRef ( variable = tmp_exit_variable , source_ref = source_ref ) , source = attribute_lookup_class ( source = ExpressionTempVariableRef ( variable = tmp_source_variable , source_ref = source_ref ) , attribute_name = ( '__exit__' if sync else '__aexit__' ) , source_ref = source_ref ) , source_ref = source_ref ) , StatementAssignmentVariable ( variable_ref = ExpressionTargetTempVariableRef ( variable = tmp_enter_variable , source_ref = source_ref ) , source = enter_value , source_ref = source_ref ) , StatementAssignmentVariable ( variable_ref = ExpressionTargetTempVariableRef ( variable = tmp_indicator_variable , source_ref = source_ref ) , source = ExpressionConstantRef ( constant = True , source_ref = source_ref ) , source_ref = source_ref ) ] #NEWLINE# statements += [ makeTryFinallyStatement ( provider = provider , tried = makeTryExceptSingleHandlerNodeWithPublish ( provider = provider , tried = with_body , exception_name = 'BaseException' , handler_body = StatementsSequence ( statements = ( StatementAssignmentVariable ( variable_ref = ExpressionTargetTempVariableRef ( variable = tmp_indicator_variable , source_ref = source_ref ) , source = ExpressionConstantRef ( constant = False , source_ref = source_ref ) , source_ref = source_ref ) , makeConditionalStatement ( condition = exit_value_exception , no_branch = makeReraiseExceptionStatement ( source_ref = with_exit_source_ref ) , yes_branch = None , source_ref = with_exit_source_ref ) ) , source_ref = source_ref ) , public_exc = ( python_version >= 270 ) , source_ref = source_ref ) , final = StatementConditional ( condition = ExpressionComparisonIs ( left = ExpressionTempVariableRef ( variable = tmp_indicator_variable , source_ref = source_ref ) , right = ExpressionConstantRef ( constant = True , source_ref = source_ref ) , source_ref = source_ref ) , yes_branch = makeStatementsSequenceFromStatement ( statement = StatementExpressionOnly ( expression = exit_value_no_exception , source_ref = source_ref ) ) , no_branch = None , source_ref = source_ref ) , source_ref = source_ref ) ] #NEWLINE# return makeTryFinallyStatement ( provider = provider , tried = statements , final = ( StatementReleaseVariable ( variable = tmp_source_variable , source_ref = with_exit_source_ref ) , StatementReleaseVariable ( variable = tmp_enter_variable , source_ref = with_exit_source_ref ) , StatementReleaseVariable ( variable = tmp_exit_variable , source_ref = with_exit_source_ref ) , StatementReleaseVariable ( variable = tmp_indicator_variable , source_ref = with_exit_source_ref ) ) , source_ref = source_ref )