equal
deleted
inserted
replaced
77 self.token = token |
77 self.token = token |
78 |
78 |
79 def __str__(self): |
79 def __str__(self): |
80 return self.token |
80 return self.token |
81 |
81 |
|
82 class String (Field): |
|
83 """ |
|
84 A quoted string |
|
85 """ |
|
86 |
|
87 def __init__(self, string): |
|
88 self.string = string |
|
89 |
|
90 def __str__(self): |
|
91 # TODO: escape |
|
92 return '"{self.string}"'.format(self=self) |
|
93 |
82 def quote (value, context=None): |
94 def quote (value, context=None): |
83 """ |
95 """ |
84 Build a single field as part of a dhcp.conf line. |
96 Build a single field as part of a dhcp.conf line. |
85 |
97 |
86 >>> print quote('foo') |
98 >>> print quote('foo') |
101 192.0.2.1 |
113 192.0.2.1 |
102 >>> print quote('00:11:22:33:44:55', context=('hardware', 'ethernet')) |
114 >>> print quote('00:11:22:33:44:55', context=('hardware', 'ethernet')) |
103 00:11:22:33:44:55 |
115 00:11:22:33:44:55 |
104 >>> print quote(Field('1:00:11:22:33:44:55')) |
116 >>> print quote(Field('1:00:11:22:33:44:55')) |
105 1:00:11:22:33:44:55 |
117 1:00:11:22:33:44:55 |
|
118 >>> print quote(String('foobar')) |
|
119 "foobar" |
106 """ |
120 """ |
107 |
121 |
108 if isinstance(value, Field): |
122 if isinstance(value, Field): |
109 return str(value) |
123 return str(value) |
110 elif isinstance(value, int): |
124 elif isinstance(value, int): |