--- 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):
--- 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()
)