pypet/naturalnaming.py
def _to_dict(self, node, fast_access=True, short_names=False, nested=False,
                 copy=True, with_links=True):
        """ Returns a dictionary with pairings of (full) names as keys and instances as values.

        :param fast_access:

            If true parameter or result values are returned instead of the
            instances.

        :param short_names:

            If true keys are not full names but only the names.
            Raises a ValueError if the names are not unique.

        :param nested:

            If true returns a nested dictionary.

        :param with_links:

            If links should be considered

        :return: dictionary

        :raises: ValueError

        """

        if (fast_access or short_names or nested) and not copy:
            raise ValueError('You can not request the original data with >>fast_access=True<< or'
                             ' >>short_names=True<< of >>nested=True<<.')

        if nested and short_names:
            raise ValueError('You cannot use short_names and nested at the '
                             'same time.')

        # First, let's check if we can return the `flat_leaf_storage_dict` or a copy of that, this
        # is faster than creating a novel dictionary by tree traversal.
        if node.v_is_root:
            temp_dict = self._flat_leaf_storage_dict

            if not fast_access and not short_names:
                if copy:
                    return temp_dict.copy()
                else:
                    return temp_dict

            else:
                iterator = temp_dict.values()
        else:
            iterator = node.f_iter_leaves(with_links=with_links)

        # If not we need to build the dict by iterating recursively over all leaves:
        result_dict = {}
        for val in iterator:
            if short_names:
                new_key = val.v_name
            else:
                new_key = val.v_full_name

            if new_key in result_dict:
                raise ValueError('Your short names are not unique. '
                                 'Duplicate key `%s`!' % new_key)

            new_val = self._apply_fast_access(val, fast_access)
            result_dict[new_key] = new_val

        if nested:
            if node.v_is_root:
                nest_dict = result_dict
            else:
                # remove the name of the current node
                # such that the nested dictionary starts with the children
                strip = len(node.v_full_name) + 1
                nest_dict = {key[strip:]: val for key, val in result_dict.items()}
            result_dict = nest_dictionary(nest_dict, '.')

        return result_dict
def _to_dict(self, node, fast_access=True, short_names=False, nested=False,
                 copy=True, with_links=True):
        """ Returns a dictionary with pairings of (full) names as keys and instances as values.

        :param fast_access:

            If true parameter or result values are returned instead of the
            instances.

        :param short_names:

            If true keys are not full names but only the names.
            Raises a ValueError if the names are not unique.

        :param nested:

            If true returns a nested dictionary.

        :param with_links:

            If links should be considered

        :return: dictionary

        :raises: ValueError

        """

        if (fast_access or short_names or nested) and not copy:
            raise ValueError('You can not request the original data with >>fast_access=True<< or'
                             ' >>short_names=True<< of >>nested=True<<.')

        if nested and short_names:
            raise ValueError('You cannot use short_names and nested at the '
                             'same time.')

        # First, let's check if we can return the `flat_leaf_storage_dict` or a copy of that, this
        # is faster than creating a novel dictionary by tree traversal.
        if node.v_is_root:
            temp_dict = self._flat_leaf_storage_dict

            if not fast_access and not short_names:
                if copy:
                    return temp_dict.copy()
                else:
                    return temp_dict

            else:
                iterator = temp_dict.values()
        else:
            iterator = node.f_iter_leaves(with_links=with_links)

        # If not we need to build the dict by iterating recursively over all leaves:
        result_dict = {}
        for val in iterator:
            if short_names:
                new_key = val.v_name
            else:
                new_key = val.v_full_name

            if new_key in result_dict:
                raise ValueError('Your short names are not unique. '
                                 'Duplicate key `%s`!' % new_key)

            new_val = self._apply_fast_access(val, fast_access)
            result_dict[new_key] = new_val

        if nested:
            if node.v_is_root:
                nest_dict = result_dict
            else:
                # remove the name of the current node
                # such that the nested dictionary starts with the children
                strip = len(node.v_full_name) + 1
                nest_dict = {key[strip:]: val for key, val in result_dict.items()}
            result_dict = nest_dictionary(nest_dict, '.')

        return result_dict
Returns a dictionary with pairings of (full) names as keys and instances as values.

        :param fast_access:

            If true parameter or result values are returned instead of the
            instances.

        :param short_names:

            If true keys are not full names but only the names.
            Raises a ValueError if the names are not unique.

        :param nested:

            If true returns a nested dictionary.

        :param with_links:

            If links should be considered

        :return: dictionary

        :raises: ValueError