Show More
@@ -90,6 +90,7 b' class LazyConfigValue(HasTraits):' | |||||
90 |
|
90 | |||
91 | # list methods |
|
91 | # list methods | |
92 | _extend = List() |
|
92 | _extend = List() | |
|
93 | _prepend = List() | |||
93 |
|
94 | |||
94 | def append(self, obj): |
|
95 | def append(self, obj): | |
95 | self._extend.append(obj) |
|
96 | self._extend.append(obj) | |
@@ -97,6 +98,10 b' class LazyConfigValue(HasTraits):' | |||||
97 | def extend(self, other): |
|
98 | def extend(self, other): | |
98 | self._extend.extend(other) |
|
99 | self._extend.extend(other) | |
99 |
|
100 | |||
|
101 | def prepend(self, other): | |||
|
102 | """like list.extend, but for the front""" | |||
|
103 | self._prepend[:0] = other | |||
|
104 | ||||
100 | _inserts = List() |
|
105 | _inserts = List() | |
101 | def insert(self, index, other): |
|
106 | def insert(self, index, other): | |
102 | if not isinstance(index, int): |
|
107 | if not isinstance(index, int): | |
@@ -129,7 +134,9 b' class LazyConfigValue(HasTraits):' | |||||
129 | if isinstance(value, list): |
|
134 | if isinstance(value, list): | |
130 | for idx, obj in self._inserts: |
|
135 | for idx, obj in self._inserts: | |
131 | value.insert(idx, obj) |
|
136 | value.insert(idx, obj) | |
|
137 | value[:0] = self._prepend | |||
132 | value.extend(self._extend) |
|
138 | value.extend(self._extend) | |
|
139 | ||||
133 | elif isinstance(value, dict): |
|
140 | elif isinstance(value, dict): | |
134 | if self._update: |
|
141 | if self._update: | |
135 | value.update(self._update) |
|
142 | value.update(self._update) | |
@@ -142,13 +149,15 b' class LazyConfigValue(HasTraits):' | |||||
142 | def to_dict(self): |
|
149 | def to_dict(self): | |
143 | """return JSONable dict form of my data |
|
150 | """return JSONable dict form of my data | |
144 |
|
151 | |||
145 | Currently update as dict or set, extend as list, and inserts as list of tuples. |
|
152 | Currently update as dict or set, extend, prepend as lists, and inserts as list of tuples. | |
146 | """ |
|
153 | """ | |
147 | d = {} |
|
154 | d = {} | |
148 | if self._update: |
|
155 | if self._update: | |
149 | d['update'] = self._update |
|
156 | d['update'] = self._update | |
150 | if self._extend: |
|
157 | if self._extend: | |
151 | d['extend'] = self._extend |
|
158 | d['extend'] = self._extend | |
|
159 | if self._prepend: | |||
|
160 | d['prepend'] = self._prepend | |||
152 | elif self._inserts: |
|
161 | elif self._inserts: | |
153 | d['inserts'] = self._inserts |
|
162 | d['inserts'] = self._inserts | |
154 | return d |
|
163 | return d |
General Comments 0
You need to be logged in to leave comments.
Login now