Exemplo n.º 1
0
    def _get_explicit_connections(self):
        """
        Returns
        -------
        dict
            Explicit connections in this `Group`, represented as a mapping
            from the pathname of the target to the pathname of the source.
        """
        connections = {}
        for sub in self.subgroups():
            connections.update(sub._get_explicit_connections())

        for tgt, srcs in self._src.items():
            for src in srcs:
                try:
                    src_pathnames = get_absvarpathnames(src, self._unknowns_dict, 'unknowns')
                except KeyError as error:
                    try:
                        src_pathnames = get_absvarpathnames(src, self._params_dict, 'params')
                    except KeyError as error:
                        raise ConnectError.nonexistent_src_error(src, tgt)

                try:
                    for tgt_pathname in get_absvarpathnames(tgt, self._params_dict, 'params'):
                        connections.setdefault(tgt_pathname, []).extend(src_pathnames)
                except KeyError as error:
                    try:
                        get_absvarpathnames(tgt, self._unknowns_dict, 'unknowns')
                    except KeyError as error:
                        raise ConnectError.nonexistent_target_error(src, tgt)
                    else:
                        raise ConnectError.invalid_target_error(src, tgt)

        return connections
Exemplo n.º 2
0
    def _get_explicit_connections(self):
        """
        Returns
        -------
        dict
            Explicit connections in this `Group`, represented as a mapping
            from the pathname of the target to the pathname of the source.
        """
        connections = {}
        for sub in self.subgroups():
            connections.update(sub._get_explicit_connections())

        for tgt, srcs in self._src.items():
            for src in srcs:
                try:
                    src_pathnames = get_absvarpathnames(src, self._unknowns_dict, 'unknowns')
                except KeyError as error:
                    try:
                        # if src is a param, it must use scoped absolute naming, so convert to top
                        # level absolute name for lookup in params_dict
                        s = self._get_var_pathname(src)
                        # verify that src is actually in self._params_dict
                        self._params_dict[s]
                        src_pathnames = [s]
                    except KeyError as error:
                        raise ConnectError.nonexistent_src_error(src, tgt)

                try:
                    for tgt_pathname in get_absvarpathnames(tgt, self._params_dict, 'params'):
                        connections.setdefault(tgt_pathname, []).extend(src_pathnames)
                except KeyError as error:
                    try:
                        get_absvarpathnames(tgt, self._unknowns_dict, 'unknowns')
                    except KeyError as error:
                        raise ConnectError.nonexistent_target_error(src, tgt)
                    else:
                        raise ConnectError.invalid_target_error(src, tgt)

        return connections