#NEWLINE# def nested_dict_merge( d1 , d2 ) : #NEWLINE# #INDENT# merged = d1 . copy ( ) #NEWLINE# for ( k , v ) in d2 . iteritems ( ) : #NEWLINE# #INDENT# if merged . has_key ( k ) : #NEWLINE# #INDENT# if ( type ( merged [ k ] ) is dict ) : #NEWLINE# #INDENT# merged [ k ] = nested_dict_merge ( merged [ k ] , merged ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# raise KeyError ( ( 'Collision in key %s type %s' % ( k , type ( merged [ k ] ) ) ) ) #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# merged [ k ] = v #NEWLINE# #UNINDENT# #UNINDENT# return merged