Пример #1
0
 def _interpolate_render_from_external(self, context, path, value):
     try:
         new = value.render(context, None, self._options)
     except UndefinedVariableError as e:
         raise UndefinedVariableError(e.var, path)
     if isinstance(new, dict):
         self._render_simple_dict(new, path)
     elif isinstance(new, list):
         self._render_simple_list(new, path)
     return new
Пример #2
0
    def _interpolate_render_value(self, path, value, inventory):
        try:
            new = value.render(self._base, inventory, self._options)
        except UndefinedVariableError as e:
            raise UndefinedVariableError(e.var, path)

        if isinstance(new, dict):
            self._render_simple_dict(new, path)
        elif isinstance(new, list):
            self._render_simple_list(new, path)
        return new
Пример #3
0
    def _interpolate_inner(self, path, refvalue):
        self._occurrences[path] = True  # mark as seen
        for ref in refvalue.get_references():
            path_from_ref = DictPath(self.delimiter, ref)
            try:
                refvalue_inner = self._occurrences[path_from_ref]

                # If there is no reference, then this will throw a KeyError,
                # look further down where this is caught and execution passed
                # to the next iteration of the loop
                #
                # If we get here, then the ref references another parameter,
                # requiring us to recurse, dereferencing first those refs that
                # are most used and are thus at the leaves of the dependency
                # tree.

                if refvalue_inner is True:
                    # every call to _interpolate_inner replaces the value of
                    # the saved occurrences of a reference with True.
                    # Therefore, if we encounter True instead of a refvalue,
                    # it means that we have already processed it and are now
                    # faced with a cyclical reference.
                    raise InfiniteRecursionError(path, ref)
                self._interpolate_inner(path_from_ref, refvalue_inner)

            except KeyError as e:
                # not actually an error, but we are done resolving all
                # dependencies of the current ref, so move on
                continue

        try:
            new = refvalue.render(self._base)
            path.set_value(self._base, new)

            # finally, remove the reference from the occurrences cache
            del self._occurrences[path]
        except UndefinedVariableError as e:
            raise UndefinedVariableError(e.var, path)
Пример #4
0
 def _resolve(self, ref, context):
     path = DictPath(self._delim, ref)
     try:
         return path.get_value(context)
     except KeyError as e:
         raise UndefinedVariableError(ref)
Пример #5
0
 def resolve(self, context, *args, **kwargs):
     path = DictPath(kwargs['delim'], self.string)
     try:
         return path.get_value(context)
     except KeyError as e:
         raise UndefinedVariableError(self.string)
Пример #6
0
 def _resolve(self, path, dictionary):
     try:
         return path.get_value(dictionary)
     except KeyError as e:
         raise UndefinedVariableError(str(path))