#NEWLINE# @ staticmethod #NEWLINE# def merge( co_source , co_input , location = UNKNOWN , ins_lineno = ( - 1 ) , ins_offset = ( - 1 ) , ins_import_names = None ) : #NEWLINE# #INDENT# '\n      The merger makes sure that the bytecode is properly inserted where\n      it should be, but also that the consts/names/locals/etc. are re-indexed.\n      We will always append at the end of the current tuples.\n\n      We need to first compute the new bytecode resolve the jumps, and then dump it...\n      if we just emit it as right now, we have an issue since we cannot know where an\n      absolute/relative jump will land since some instr code can be inserted in between.\n    ' #NEWLINE# if ( not co_input ) : #NEWLINE# #INDENT# raise Exception ( 'Input code_object is None' ) #NEWLINE# #UNINDENT# new_co = CodeObject ( co_source ) #NEWLINE# new_co . merge_fields ( co_input ) #NEWLINE# new_co . reset_code ( ) #NEWLINE# bc_source = BytecodeObject . get_parsed_code ( co_source ) #NEWLINE# bc_input = BytecodeObject . get_parsed_code ( co_input ) [ : ( - 2 ) ] #NEWLINE# if ins_import_names : #NEWLINE# #INDENT# for name in ins_import_names : #NEWLINE# #INDENT# new_co . add_global_name ( name ) #NEWLINE# #UNINDENT# #UNINDENT# new_bytecode = None #NEWLINE# if ( location == Merger . MODULE_EXIT ) : #NEWLINE# #INDENT# new_bytecode = Merger . merge_exit ( new_co , bc_source , bc_input , ins_import_names ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if Merger . already_instrumented ( bc_source , bc_input ) : #NEWLINE# #INDENT# logger . debug ( 'Already instrumented code object. Skipping' ) #NEWLINE# return #NEWLINE# #UNINDENT# bytecode = Merger . get_final_bytecode ( bc_source , bc_input , co_source , co_input , location , ins_lineno , ins_offset ) #NEWLINE# new_bytecode = Merger . resolve_jump_targets ( bytecode , new_co ) #NEWLINE# #UNINDENT# for bc_tpl in new_bytecode : #NEWLINE# #INDENT# new_co . append ( bc_tpl [ 0 ] [ 2 ] , bc_tpl [ 0 ] [ 3 ] , bc_tpl [ 0 ] [ 0 ] , bc_tpl [ 0 ] [ 1 ] ) #NEWLINE# #UNINDENT# final_new_co = new_co . to_code ( ) #NEWLINE# return final_new_co