Ejemplo n.º 1
0
    def get(self, key, from_self=True, from_templates=True,
            from_defaults=True):
        """
        Get the values corresponding to a given key. The parameters to this
        function form a hierarchy that determines priority of the search.
        from_self takes priority over from_templates, and from_templates takes
        priority over from_defaults.

        Parameters:
        from_self - If True, search within the given section.
        from_templates - If True, search in this section's templates.
        from_defaults - If True, search within this section's defaults.
        """
        if from_self and key in self:
            return MultiOrderedDict.__getitem__(self, key)

        if from_templates:
            if self in self._templates:
                return []
            for t in self._templates:
                try:
                    # fail if not found on the search - doing it this way
                    # allows template's templates to be searched.
                    return t.get(key, True, from_templates, from_defaults)
                except KeyError:
                    pass

        if from_defaults:
            for d in self._defaults:
                try:
                    return d.get(key, True, from_templates, from_defaults)
                except KeyError:
                    pass

        raise KeyError(key)
Ejemplo n.º 2
0
    def get(self, key, from_self=True, from_templates=True,
            from_defaults=True):
        """
        Get the values corresponding to a given key. The parameters to this
        function form a hierarchy that determines priority of the search.
        from_self takes priority over from_templates, and from_templates takes
        priority over from_defaults.

        Parameters:
        from_self - If True, search within the given section.
        from_templates - If True, search in this section's templates.
        from_defaults - If True, search within this section's defaults.
        """
        if from_self and key in self:
            return MultiOrderedDict.__getitem__(self, key)

        if from_templates:
            if self in self._templates:
                return []
            for t in self._templates:
                try:
                    # fail if not found on the search - doing it this way
                    # allows template's templates to be searched.
                    return t.get(key, True, from_templates, from_defaults)
                except KeyError:
                    pass

        if from_defaults:
            for d in self._defaults:
                try:
                    return d.get(key, True, from_templates, from_defaults)
                except KeyError:
                    pass

        raise KeyError(key)
Ejemplo n.º 3
0
    def get(self, key, from_self=True, from_templates=True, from_defaults=True):
        if from_self and key in self:
            return MultiOrderedDict.__getitem__(self, key)

        if from_templates:
            if self in self._templates:
                return []
            for t in self._templates:
                try:
                    # fail if not found on the search - doing it this way
                    # allows template's templates to be searched.
                    return t.get(key, True, from_templates, from_defaults)
                except KeyError:
                    pass

        if from_defaults:
            for d in self._defaults:
                try:
                    return d.get(key, True, from_templates, from_defaults)
                except KeyError:
                    pass

        raise KeyError(key)