# HG changeset patch # User Tero Marttila # Date 1425252596 -7200 # Node ID 60dbd952a15e5ec75613fafd41568baed263fa5f # Parent 3da02c7e57813262f0540b33a16f0832e94d1f56 pvl.dhcp.config: fix block stack to have .load() actually return the top-level block diff -r 3da02c7e5781 -r 60dbd952a15e pvl/dhcp/config.py --- a/pvl/dhcp/config.py Mon Mar 02 01:24:48 2015 +0200 +++ b/pvl/dhcp/config.py Mon Mar 02 01:29:56 2015 +0200 @@ -121,7 +121,7 @@ return ' '.join(self.key) def __repr__ (self): - return "Block({self.key!r}, items={self.items!r}, blocks={self.blocks!r}".format(self=self) + return "Block({self.key!r}, items={self.items!r}, blocks={self.blocks!r})".format(self=self) class DHCPConfigParser (object): """ @@ -138,7 +138,7 @@ Parse an complete file, returning the top-level Block. >>> DHCPConfigParser.load(['foo;', 'bar {', '\tasdf "quux";', '}'], name='test') - Block(None, items=[('foo', )], blocks=[Block(('bar', ), items=[('asdf', 'quux')], blocks=[])]) + Block(None, items=[('foo',)], blocks=[Block(('bar',), items=[('asdf', 'quux')], blocks=[])]) """ if name is None: @@ -155,7 +155,10 @@ raise if parser.token: - raise DHCPConfError(parser, "Trailing data: {token}".format(token=token), line=lineno) + raise DHCPConfError(parser, "Trailing data: {token}".format(token=parser.token), line=lineno) + + if parser.stack: + raise DHCPConfError(parser, "Unterminated block: {stack}".format(stack=parser.stack), line=lineno) return parser.block @@ -218,9 +221,9 @@ log.debug("open block: %s > %s", self.block, block) + self.stack.append(self.block) self.block.blocks.append(block) self.block = block - self.stack.append(block) # must be within block! elif token == 'item' : diff -r 3da02c7e5781 -r 60dbd952a15e pvl/dhcp/tests.py --- a/pvl/dhcp/tests.py Mon Mar 02 01:24:48 2015 +0200 +++ b/pvl/dhcp/tests.py Mon Mar 02 01:29:56 2015 +0200 @@ -92,15 +92,17 @@ hardware ethernet 00:11:22:33:44:55; } } - """)), (('group', ), [ - ('next-server', 'boot.test'), - ('filename', "/debian/wheezy/pxelinux.0"), - ('include', "hosts/test.conf"), - ], [ - (('host', 'foo'), [ - ('fixed-address', '192.0.2.1'), - ('hardware', 'ethernet', '00:11:22:33:44:55'), - ], []) + """)), (None, [], [ + (('group', ), [ + ('next-server', 'boot.test'), + ('filename', "/debian/wheezy/pxelinux.0"), + ('include', "hosts/test.conf"), + ], [ + (('host', 'foo'), [ + ('fixed-address', '192.0.2.1'), + ('hardware', 'ethernet', '00:11:22:33:44:55'), + ], []) + ]), ])) class ConfigBuildTest(unittest.TestCase):