#NEWLINE# def insert_stage( self , stage , index = None , after = None , before = None , replace = None , only_if = True ) : #NEWLINE# #INDENT# if only_if : #NEWLINE# #INDENT# if ( sum ( ( ( x is not None ) for x in ( index , after , before , replace ) ) ) != 1 ) : #NEWLINE# #INDENT# raise ValueError ( 'Must specify exactly one of arguments: index, after, before, replace' ) #NEWLINE# #UNINDENT# if ( index is not None ) : #NEWLINE# #INDENT# indices = ( index , ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( after is not None ) : #NEWLINE# #INDENT# indices = tuple ( ( ( i + 1 ) for ( i , x ) in enumerate ( self ) if isinstance ( x , after ) ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( before is not None ) : #NEWLINE# #INDENT# indices = tuple ( ( i for ( i , x ) in enumerate ( self ) if isinstance ( x , before ) ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( replace is not None ) : #NEWLINE# #INDENT# for ( i , x ) in enumerate ( self ) : #NEWLINE# #INDENT# if isinstance ( x , replace ) : #NEWLINE# #INDENT# self [ i ] = stage #NEWLINE# #UNINDENT# #UNINDENT# return self #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# for i in reversed ( indices ) : #NEWLINE# #INDENT# self . insert ( i , stage ) #NEWLINE# #UNINDENT# #UNINDENT# return self