diff --git a/tuned/profiles/functions/functions.py b/tuned/profiles/functions/functions.py index 68ce234..acf7077 100644 --- a/tuned/profiles/functions/functions.py +++ b/tuned/profiles/functions/functions.py @@ -32,8 +32,8 @@ class Functions(): def _curr_substr(self, _len): return self._str[self._cnt:self._cnt + _len] - def _push_pos(self): - self._stack.append(self._cnt) + def _push_pos(self, esc): + self._stack.append((esc, self._cnt)) def _sub(self, a, b, s): self._str = self._str[:a] + s + self._str[b + 1:] @@ -63,20 +63,21 @@ class Functions(): def _process(self, s): self._parse_init(s) while self._cnt < self._len: - if self._esc: - self._esc = False + if self._curr_char() == "}": + try: + si = self._stack.pop() + except IndexError: + log.error("invalid variable syntax, non pair '}' in: '%s'" % s) + return self._str + # if not escaped + if not si[0]: + self._process_func(si[1]) + elif self._curr_substr(2) == "${": + self._push_pos(self._esc) + if self._curr_char() == "\\": + self._esc = True else: - if self._curr_char() == "\\": - self._esc = True - elif self._curr_char() == "}": - try: - _from = self._stack.pop() - except IndexError: - log.error("invalid variable syntax, non pair '}' in: '%s'" % s) - return self._str - self._process_func(_from) - elif self._curr_substr(2) == "${": - self._push_pos() + self._esc = False self._cnt += 1 if len(self._stack): log.error("invalid varialbe syntax, non pair '{' in: '%s'" % s) @@ -86,4 +87,4 @@ class Functions(): if s is None or s == "": return s # expand functions and convert all \${f:*} to ${f:*} (unescape) - return re.sub(r'\\(\${f:.*\\})', r'\1', self._process(s)) + return re.sub(r'\\(\${f:.*})', r'\1', self._process(s))