def merge_dict_from_to(d1, d2):
 for (k, v) in list(d1.items()):
  if (k in d2):
   if isinstance(v, type(d2[k])):
    if isinstance(v, dict):
     merge_dict_from_to(d1[k], d2[k])
    elif isinstance(v, list):
     d2[k].extend(copy.deepcopy(v))
    elif isinstance(v, (basestring, bool, int, float, type(None))):
     pass
    else:
     raise Exception((u'Unknown type: %s value: %s in dictionary' % (type(v), repr(v))))
   elif (isinstance(v, (basestring, bool, int, float, type(None))) and isinstance(d2[k], (basestring, bool, int, float, type(None)))):
    pass
   else:
    raise MergeException((u'Merging key %s failed, conflicting datatypes %r vs. %r.' % (k, type(v).__name__, type(d2[k]).__name__)))
  else:
   d2[k] = copy.deepcopy(v)

def merge_dict_from_to ( d1 , d2 ) : for ( k , v ) in list ( d1 . items ( ) ) : if ( k in d2 ) : if isinstance ( v , type ( d2 [ k ] ) ) : if isinstance ( v , dict ) : merge_dict_from_to ( d1 [ k ] , d2 [ k ] ) elif isinstance ( v , list ) : d2 [ k ] . extend ( copy . deepcopy ( v ) ) elif isinstance ( v , ( basestring , bool , int , float , type ( None ) ) ) : pass else : raise Exception ( ( u'Unknown type: %s value: %s in dictionary' % ( type ( v ) , repr ( v ) ) ) ) elif ( isinstance ( v , ( basestring , bool , int , float , type ( None ) ) ) and isinstance ( d2 [ k ] , ( basestring , bool , int , float , type ( None ) ) ) ) : pass else : raise MergeException ( ( u'Merging key %s failed, conflicting datatypes %r vs. %r.' % ( k , type ( v ) . __name__ , type ( d2 [ k ] ) . __name__ ) ) ) else : d2 [ k ] = copy . deepcopy ( v )
merges dictionary d1 into dictionary d2 .