Fix to inlinefuncs stack cache to make it properly use the cached value.

This commit is contained in:
Griatch 2017-01-29 16:52:06 +01:00
parent 203d0a09a0
commit dcde526f6d

View file

@ -266,14 +266,14 @@ def parse_inlinefunc(string, strip=False, **kwargs):
if string in _PARSING_CACHE: if string in _PARSING_CACHE:
# stack is already cached # stack is already cached
stack = _PARSING_CACHE[string] stack = _PARSING_CACHE[string]
else: elif not _RE_STARTTOKEN.search(string):
# not a cached string.
if not _RE_STARTTOKEN.search(string):
# if there are no unescaped start tokens at all, return immediately. # if there are no unescaped start tokens at all, return immediately.
return string return string
else:
# build a new cache entry # no cached stack; build a new stack and continue
stack = ParseStack() stack = ParseStack()
# process string on stack
ncallable = 0 ncallable = 0
for match in _RE_TOKEN.finditer(string): for match in _RE_TOKEN.finditer(string):
gdict = match.groupdict() gdict = match.groupdict()
@ -329,7 +329,7 @@ def parse_inlinefunc(string, strip=False, **kwargs):
# if stack is larger than limit, throw away parsing # if stack is larger than limit, throw away parsing
return string + gdict["stackfull"](*args, **kwargs) return string + gdict["stackfull"](*args, **kwargs)
else: else:
# cache the result # cache the stack
_PARSING_CACHE[string] = stack _PARSING_CACHE[string] = stack
# run the stack recursively # run the stack recursively
@ -356,6 +356,7 @@ def parse_inlinefunc(string, strip=False, **kwargs):
# execute the stack from the cache # execute the stack from the cache
return "".join(_run_stack(item) for item in _PARSING_CACHE[string]) return "".join(_run_stack(item) for item in _PARSING_CACHE[string])
#
# Nick templating # Nick templating
# #