예제 #1
0
    def resolve_str(self,
                    src: str,
                    unwrap=True,
                    skip_interpolation_checks=False) -> str:
        """Resolves interpolated string to it's original value,
        or in case of multiple interpolations, a combined string.

        >>> c = Context({"enabled": True})
        >>> c.resolve_str("${enabled}")
        True
        >>> c.resolve_str("enabled? ${enabled}")
        'enabled? true'
        """
        matches = get_matches(src)
        if is_exact_string(src, matches):
            # replace "${enabled}", if `enabled` is a boolean, with it's actual
            # value rather than it's string counterparts.
            expr = get_expression(matches[0],
                                  skip_checks=skip_interpolation_checks)
            return self.select(expr, unwrap=unwrap)
        # but not "${num} days"
        return str_interpolate(src,
                               matches,
                               self,
                               skip_checks=skip_interpolation_checks)
예제 #2
0
 def _check_joined_with_interpolation(key: str, value: str):
     matches = get_matches(value)
     if matches and not is_exact_string(value, matches):
         raise ValueError(
             f"Cannot set '{key}', "
             "joining string with interpolated string "
             "is not supported"
         )