Commit edc108ea authored by Antoine Catton's avatar Antoine Catton Committed by Łukasz Nowak

Bug #664539 fix.

This fix was already done by Roman. But the escape_data dict cache was
posing problem in specific complex case. (Notably in
collective.recipe.template tests).
To keep the last fix, we would have to change every method of Options
class.

This fix does not use escape_data dict cache. This way, it allow
a simple working fix with minimal impact. Not breaking backward
compatibility.
parent e5ef240b
......@@ -1353,12 +1353,16 @@ class Options(UserDict.DictMixin):
def _dosub(self, option, v):
__doing__ = 'Getting option %s:%s.', self.name, option
seen = [(self.name, option)]
v = '$$'.join([self._sub(s, seen) for s in v.split('$$')])
v = '$$'.join([self._sub(s, seen, lastlevel=False)
for s in v.split('$$')])
self._cooked[option] = v
def get(self, option, default=None, seen=None):
def get(self, option, default=None, seen=None, lastlevel=True):
try:
return self._data[option]
if lastlevel:
return self._data[option].replace('$${', '${')
else:
return self._data[option]
except KeyError:
pass
......@@ -1380,16 +1384,20 @@ class Options(UserDict.DictMixin):
)
else:
seen.append(key)
v = '$$'.join([self._sub(s, seen) for s in v.split('$$')])
v = '$$'.join([self._sub(s, seen, lastlevel=False)
for s in v.split('$$')])
seen.pop()
self._data[option] = v
return v
if lastlevel:
return v.replace('$${', '${')
else:
return v
_template_split = re.compile('([$]{[^}]*})').split
_simple = re.compile('[-a-zA-Z0-9 ._]+$').match
_valid = re.compile('\${[-a-zA-Z0-9 ._]*:[-a-zA-Z0-9 ._]+}$').match
def _sub(self, template, seen):
def _sub(self, template, seen, lastlevel=True):
value = self._template_split(template)
subs = []
for ref in value[1::2]:
......@@ -1417,7 +1425,8 @@ class Options(UserDict.DictMixin):
section, option = s
if not section:
section = self.name
v = self.buildout[section].get(option, None, seen)
v = self.buildout[section].get(option, None, seen,
lastlevel=lastlevel)
if v is None:
if option == '_buildout_section_name_':
v = self.name
......@@ -1430,11 +1439,6 @@ class Options(UserDict.DictMixin):
return ''.join([''.join(v) for v in zip(value[::2], subs)])
def __getitem__(self, key):
try:
return self._data[key]
except KeyError:
pass
v = self.get(key)
if v is None:
raise MissingOption("Missing option: %s:%s" % (self.name, key))
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment