equal
deleted
inserted
replaced
66 if item is None: |
66 if item is None: |
67 break |
67 break |
68 |
68 |
69 yield item |
69 yield item |
70 |
70 |
|
71 class Field (object): |
|
72 """ |
|
73 Pre-quoted fields for use in DHCP confs. |
|
74 """ |
|
75 |
|
76 def __init__(self, token): |
|
77 self.token = token |
|
78 |
|
79 def __str__(self): |
|
80 return self.token |
|
81 |
71 def quote (value, context=None): |
82 def quote (value, context=None): |
72 """ |
83 """ |
73 Build a single field as part of a dhcp.conf line. |
84 Build a single field as part of a dhcp.conf line. |
74 |
85 |
75 >>> print quote('foo') |
86 >>> print quote('foo') |
88 foo.bar |
99 foo.bar |
89 >>> print quote('192.0.2.1', context=('fixed-address', )) |
100 >>> print quote('192.0.2.1', context=('fixed-address', )) |
90 192.0.2.1 |
101 192.0.2.1 |
91 >>> print quote('00:11:22:33:44:55', context=('hardware', 'ethernet')) |
102 >>> print quote('00:11:22:33:44:55', context=('hardware', 'ethernet')) |
92 00:11:22:33:44:55 |
103 00:11:22:33:44:55 |
93 """ |
104 >>> print quote(Field('1:00:11:22:33:44:55')) |
94 |
105 1:00:11:22:33:44:55 |
95 if isinstance(value, int): |
106 """ |
|
107 |
|
108 if isinstance(value, Field): |
|
109 return str(value) |
|
110 elif isinstance(value, int): |
96 return str(value) |
111 return str(value) |
97 elif context in UNQUOTED_CONTEXT: |
112 elif context in UNQUOTED_CONTEXT: |
98 return str(value) |
113 return str(value) |
99 elif value[0] in TOKEN_START and all(c in TOKEN for c in value): |
114 elif value[0] in TOKEN_START and all(c in TOKEN for c in value): |
100 return str(value) |
115 return str(value) |