Mercurial > iscconf
changeset 5:d0c1181969ba
Fix comment parsing
| author | Radomir Dopieralski <radomir.dopieralski@allegro.pl> |
|---|---|
| date | Tue, 26 Jun 2012 14:51:46 +0200 |
| parents | b1e8f8a90853 |
| children | db918011f419 |
| files | iscconf/parser.py setup.py tests/test_dhcp.py |
| diffstat | 3 files changed, 23 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/iscconf/parser.py Tue Jun 26 14:33:18 2012 +0200 +++ b/iscconf/parser.py Tue Jun 26 14:51:46 2012 +0200 @@ -15,7 +15,7 @@ t_BRACE_OPEN = r'{' t_BRACE_CLOSE = r'}' t_SEMICOLON = ';' -t_ignore_COMMENT = r'^[#].*$' +t_ignore_COMMENT = r'[#][^\n]*' class Error(Exception):
--- a/setup.py Tue Jun 26 14:33:18 2012 +0200 +++ b/setup.py Tue Jun 26 14:51:46 2012 +0200 @@ -3,6 +3,8 @@ setup( name='iscconf', description="Parser for ISC configuration files.", + author="Radomir Dopieralski", + author_email="devel@sheep.art.pl", long_description=""" Parser for ISC configuration files, such as ``dhcpd.conf`` or ``named.conf``. """,
--- a/tests/test_dhcp.py Tue Jun 26 14:33:18 2012 +0200 +++ b/tests/test_dhcp.py Tue Jun 26 14:51:46 2012 +0200 @@ -10,6 +10,10 @@ data = iscconf.parse('') self.assertEqual(data, {}) + def test_empty_comment(self): + data = iscconf.parse('# xxx') + self.assertEqual(data, {}) + def test_single(self): data = iscconf.parse("""\ host s10557.dc2 { @@ -23,6 +27,22 @@ }, }) + def test_single_comments(self): + data = iscconf.parse("""\ +# comment +host s10557.dc2 { +# comment + fixed-address 10.242.15.6; + hardware ethernet 00:1b:78:cf:b3:90; +} +# comment +""") + self.assertEqual(data, { + ('host', 's10557.dc2'): { + ('fixed-address',): '10.242.15.6', + ('hardware', 'ethernet'): '00:1b:78:cf:b3:90', + }, + }) def test_multi(self): data = iscconf.parse("""\ host s10557.dc2 {
