Skip to content
This repository has been archived by the owner on Feb 13, 2020. It is now read-only.

Commit

Permalink
Merge pull request #1 from zopefoundation/fix-parse
Browse files Browse the repository at this point in the history
- Fixed: When parsing configuration text, sections were input and
  • Loading branch information
freddrake committed Jan 24, 2014
2 parents 3cedaff + 3ef2ca8 commit 9e4aaaf
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 3 deletions.
5 changes: 5 additions & 0 deletions src/zc/metarecipe/README.txt
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,11 @@ That's pretty much it.
Changes
=======

- Fixed: When parsing configuration text, sections were input and
evaluated at the same time in section sorted order. This
caused problems if a section that sorted early referred to a
section that sorted late.

0.2.0 (2012-09-24)
------------------

Expand Down
11 changes: 8 additions & 3 deletions src/zc/metarecipe/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,14 @@ def __setitem__(self, name, data):
def parse(self, data):
parser = ConfigParser.RawConfigParser()
parser.readfp(cStringIO.StringIO(textwrap.dedent(data)))

for section in sorted(parser.sections()):
self[section] = dict(parser.items(section))
buildout = self.buildout
raw = buildout._raw
sections = sorted(parser.sections())

for section in sections:
raw[section] = dict(parser.items(section))
for section in sections:
buildout[section]

validtypes = unicode, int

Expand Down
21 changes: 21 additions & 0 deletions src/zc/metarecipe/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,27 @@ def test_funky_option_types():
"""

class Dict(dict):

def __setitem__(self, name, value):
print 'raw setitem', name, value
dict.__setitem__(self, name, value)

def parse_does_raw_before_calling_getitem():
r"""
>>> import zc.metarecipe.testing
>>> buildout = zc.metarecipe.testing.Buildout()
>>> buildout._raw = Dict()
>>> recipe = zc.metarecipe.Recipe(buildout, '', {})
>>> recipe.parse("[a]\nx=1\n[b]\ny=2\n")
raw setitem a {'x': '1'}
raw setitem b {'y': '2'}
[a]
x = 1
[b]
y = 2
"""

def test_suite():
return unittest.TestSuite((
manuel.testing.TestSuite(
Expand Down

0 comments on commit 9e4aaaf

Please sign in to comment.