#NEWLINE# def _add_directive( block , directive , replace ) : #NEWLINE# #INDENT# 'Adds or replaces a single directive in a config block.\n\n    See _add_directives for more documentation.\n\n    ' #NEWLINE# location = ( - 1 ) #NEWLINE# for ( index , line ) in enumerate ( block ) : #NEWLINE# #INDENT# if ( ( len ( line ) > 0 ) and ( directive_value [ 0 ] == directive [ 0 ] ) ) : #NEWLINE# #INDENT# location = index #NEWLINE# break #NEWLINE# #UNINDENT# #UNINDENT# if replace : #NEWLINE# #INDENT# if ( location == ( - 1 ) ) : #NEWLINE# #INDENT# raise errors . MisconfigurationError ( ( 'expected directive for %s in the Nginx config but did not find it.' % directive [ 0 ] ) ) #NEWLINE# #UNINDENT# block [ location ] = directive #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# directive_name = directive [ 0 ] #NEWLINE# directive_value = directive [ 1 ] #NEWLINE# if ( ( location != ( - 1 ) ) and ( directive_name . __str__ ( ) not in repeatable_directives ) ) : #NEWLINE# #INDENT# if ( block [ location ] [ 1 ] == directive_value ) : #NEWLINE# #INDENT# pass #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# raise errors . MisconfigurationError ( ( 'tried to insert directive "%s" but found conflicting "%s".' % ( directive , block [ location ] ) ) ) #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# block . append ( directive )