def transfer(self, i_value_from, i_value_to, i_structure, i_structure_parent): """See :meth:`.Data_Handler.BaseTransferMgr.transfer`""" assert isinstance(i_structure, list) o_value = [] i_structure = i_structure[0] if i_value_from is not None: assert isinstance(i_value_from, list) o_value = [self.generic_transfer( value, get_class_ref(i_structure_parent, self.cb_dict)() if isinstance(i_structure, dict) else i_value_from, i_structure, i_structure_parent) for value in i_value_from] return o_value
def transfer(self, i_value_from, i_value_to, i_structure, i_structure_parent): """See :meth:`.Data_Handler.BaseTransferMgr.transfer`""" assert isinstance(i_structure, dict) # Mark this as end of recursion if i_value_from is None: return None # Encapsulate the entire process in try block to append the name of the # tag being transferred in any exceptions that are thrown. try: if i_structure_parent in _DictHandlerKeysList: return i_value_to # Ensure the structure data is of correct type assert isinstance(i_structure_parent, str) assert isinstance(i_structure, dict) # Make choices mandatory dict_choices = i_structure.get(DictHandlerKey_Choice, {}) assert isinstance(dict_choices, dict) # Loop over the available choice groups for choice_group in dict_choices.values(): assert isinstance(choice_group, dict) # Loop over the choices from the choice group for choice, choice_format in choice_group.items(): if choice in i_structure.keys(): if choice_format != i_structure[choice]: raise RuntimeError('Choice key "' + choice + '" already exists in the dictionary under: "' + str(i_structure_parent) + '"') else: i_structure[choice] = choice_format # Go over the mandatory attributes for i_structure_key, i_structure_value in i_structure.items(): if i_structure_key in _DictHandlerKeysList: continue # Ensure the structure data is of correct type assert isinstance(i_structure_key, str) # Get attribute from i_value_from try: value_from = getattr(i_value_from, i_structure_key) except Exception: raise RuntimeError('i_value_from: "' + str(i_value_from) + '" missing attribute: "' + str(i_structure_key) + '"') # Check if to_value does not exist if i_value_to is None: i_value_to = get_class_ref(i_structure_parent, self.cb_dict)() try: value_to = getattr(i_value_to, i_structure_key) except Exception: raise RuntimeError('i_value_to: "' + str(i_value_to) + '" missing attribute: "' + str(i_structure_key) + '"') # Update the to_obj_value value_to = self.generic_transfer(value_from, value_to, i_structure_value, i_structure_key) # Set value in the i_value_to setattr(i_value_to, i_structure_key, value_to) except Exception as e: raise type(e), type(e)(('' if i_structure_key is None else (i_structure_key + '->')) + str(e)), sys.exc_info()[2] return i_value_to