def ConnectAndDisconnectChildModules(old_module_dict, new_module_dict):
 old_keys = set(old_module_dict.keys())
 new_keys = set(new_module_dict.keys())
 for deleted_module_name in (old_keys - new_keys):
  if (old_module_dict[deleted_module_name] is None):
   continue
  segments = deleted_module_name.rsplit('.', 1)
  if (len(segments) == 2):
   parent_module = new_module_dict.get(segments[0])
   if (parent_module and hasattr(parent_module, segments[1])):
    delattr(parent_module, segments[1])
 for added_module_name in (new_keys - old_keys):
  if (new_module_dict[added_module_name] is None):
   continue
  segments = added_module_name.rsplit('.', 1)
  if (len(segments) == 2):
   parent_module = old_module_dict.get(segments[0])
   child_module = new_module_dict[added_module_name]
   if (parent_module and (getattr(parent_module, segments[1], None) is not child_module)):
    setattr(parent_module, segments[1], child_module)

def ConnectAndDisconnectChildModules ( old_module_dict , new_module_dict ) : old_keys = set ( old_module_dict . keys ( ) ) new_keys = set ( new_module_dict . keys ( ) ) for deleted_module_name in ( old_keys - new_keys ) : if ( old_module_dict [ deleted_module_name ] is None ) : continue segments = deleted_module_name . rsplit ( '.' , 1 ) if ( len ( segments ) == 2 ) : parent_module = new_module_dict . get ( segments [ 0 ] ) if ( parent_module and hasattr ( parent_module , segments [ 1 ] ) ) : delattr ( parent_module , segments [ 1 ] ) for added_module_name in ( new_keys - old_keys ) : if ( new_module_dict [ added_module_name ] is None ) : continue segments = added_module_name . rsplit ( '.' , 1 ) if ( len ( segments ) == 2 ) : parent_module = old_module_dict . get ( segments [ 0 ] ) child_module = new_module_dict [ added_module_name ] if ( parent_module and ( getattr ( parent_module , segments [ 1 ] , None ) is not child_module ) ) : setattr ( parent_module , segments [ 1 ] , child_module )
prepares for switching from old_module_dict to new_module_dict .