# HG changeset patch # User Tero Marttila # Date 1425319092 -7200 # Node ID d34567c1b21ab731ea509acb389431c8c9202d41 # Parent 656178fb86072a0903999bca2efa91afe8401688 pvl.dhcp.config: String() for quoted string Field diff -r 656178fb8607 -r d34567c1b21a pvl/dhcp/config.py --- a/pvl/dhcp/config.py Mon Mar 02 19:45:56 2015 +0200 +++ b/pvl/dhcp/config.py Mon Mar 02 19:58:12 2015 +0200 @@ -79,6 +79,18 @@ def __str__(self): return self.token +class String (Field): + """ + A quoted string + """ + + def __init__(self, string): + self.string = string + + def __str__(self): + # TODO: escape + return '"{self.string}"'.format(self=self) + def quote (value, context=None): """ Build a single field as part of a dhcp.conf line. @@ -103,6 +115,8 @@ 00:11:22:33:44:55 >>> print quote(Field('1:00:11:22:33:44:55')) 1:00:11:22:33:44:55 + >>> print quote(String('foobar')) + "foobar" """ if isinstance(value, Field): diff -r 656178fb8607 -r d34567c1b21a pvl/dhcp/tests.py --- a/pvl/dhcp/tests.py Mon Mar 02 19:45:56 2015 +0200 +++ b/pvl/dhcp/tests.py Mon Mar 02 19:58:12 2015 +0200 @@ -156,7 +156,7 @@ ('hardware', 'ethernet', '00:11:22:33:44:55'), ]), config.Block(None, [ - ('subclass', 'debian', config.Field('1:00:11:22:33:44:55')), + ('subclass', config.String('debian'), config.Field('1:00:11:22:33:44:55')), ]), ])), """ @@ -165,6 +165,6 @@ fixed-address 192.0.2.1; hardware ethernet 00:11:22:33:44:55; } -subclass debian 1:00:11:22:33:44:55; +subclass "debian" 1:00:11:22:33:44:55; """.strip().splitlines() )