Show More
@@ -9,37 +9,6 b' from i18n import _' | |||||
9 | import error, util |
|
9 | import error, util | |
10 | import os, errno |
|
10 | import os, errno | |
11 |
|
11 | |||
12 | class sortdict(dict): |
|
|||
13 | 'a simple sorted dictionary' |
|
|||
14 | def __init__(self, data=None): |
|
|||
15 | self._list = [] |
|
|||
16 | if data: |
|
|||
17 | self.update(data) |
|
|||
18 | def copy(self): |
|
|||
19 | return sortdict(self) |
|
|||
20 | def __setitem__(self, key, val): |
|
|||
21 | if key in self: |
|
|||
22 | self._list.remove(key) |
|
|||
23 | self._list.append(key) |
|
|||
24 | dict.__setitem__(self, key, val) |
|
|||
25 | def __iter__(self): |
|
|||
26 | return self._list.__iter__() |
|
|||
27 | def update(self, src): |
|
|||
28 | for k in src: |
|
|||
29 | self[k] = src[k] |
|
|||
30 | def clear(self): |
|
|||
31 | dict.clear(self) |
|
|||
32 | self._list = [] |
|
|||
33 | def items(self): |
|
|||
34 | return [(k, self[k]) for k in self._list] |
|
|||
35 | def __delitem__(self, key): |
|
|||
36 | dict.__delitem__(self, key) |
|
|||
37 | self._list.remove(key) |
|
|||
38 | def keys(self): |
|
|||
39 | return self._list |
|
|||
40 | def iterkeys(self): |
|
|||
41 | return self._list.__iter__() |
|
|||
42 |
|
||||
43 | class config(object): |
|
12 | class config(object): | |
44 | def __init__(self, data=None): |
|
13 | def __init__(self, data=None): | |
45 | self._data = {} |
|
14 | self._data = {} | |
@@ -65,7 +34,7 b' class config(object):' | |||||
65 | del self._source[(s, n)] |
|
34 | del self._source[(s, n)] | |
66 | for s in src: |
|
35 | for s in src: | |
67 | if s not in self: |
|
36 | if s not in self: | |
68 | self._data[s] = sortdict() |
|
37 | self._data[s] = util.sortdict() | |
69 | self._data[s].update(src._data[s]) |
|
38 | self._data[s].update(src._data[s]) | |
70 | self._source.update(src._source) |
|
39 | self._source.update(src._source) | |
71 | def get(self, section, item, default=None): |
|
40 | def get(self, section, item, default=None): | |
@@ -91,7 +60,7 b' class config(object):' | |||||
91 | return self._data.get(section, {}).items() |
|
60 | return self._data.get(section, {}).items() | |
92 | def set(self, section, item, value, source=""): |
|
61 | def set(self, section, item, value, source=""): | |
93 | if section not in self: |
|
62 | if section not in self: | |
94 | self._data[section] = sortdict() |
|
63 | self._data[section] = util.sortdict() | |
95 | self._data[section][item] = value |
|
64 | self._data[section][item] = value | |
96 | if source: |
|
65 | if source: | |
97 | self._source[(section, item)] = source |
|
66 | self._source[(section, item)] = source | |
@@ -162,7 +131,7 b' class config(object):' | |||||
162 | if remap: |
|
131 | if remap: | |
163 | section = remap.get(section, section) |
|
132 | section = remap.get(section, section) | |
164 | if section not in self: |
|
133 | if section not in self: | |
165 | self._data[section] = sortdict() |
|
134 | self._data[section] = util.sortdict() | |
166 | continue |
|
135 | continue | |
167 | m = itemre.match(l) |
|
136 | m = itemre.match(l) | |
168 | if m: |
|
137 | if m: |
@@ -223,6 +223,37 b' except AttributeError:' | |||||
223 | del self[i] |
|
223 | del self[i] | |
224 | break |
|
224 | break | |
225 |
|
225 | |||
|
226 | class sortdict(dict): | |||
|
227 | '''a simple sorted dictionary''' | |||
|
228 | def __init__(self, data=None): | |||
|
229 | self._list = [] | |||
|
230 | if data: | |||
|
231 | self.update(data) | |||
|
232 | def copy(self): | |||
|
233 | return sortdict(self) | |||
|
234 | def __setitem__(self, key, val): | |||
|
235 | if key in self: | |||
|
236 | self._list.remove(key) | |||
|
237 | self._list.append(key) | |||
|
238 | dict.__setitem__(self, key, val) | |||
|
239 | def __iter__(self): | |||
|
240 | return self._list.__iter__() | |||
|
241 | def update(self, src): | |||
|
242 | for k in src: | |||
|
243 | self[k] = src[k] | |||
|
244 | def clear(self): | |||
|
245 | dict.clear(self) | |||
|
246 | self._list = [] | |||
|
247 | def items(self): | |||
|
248 | return [(k, self[k]) for k in self._list] | |||
|
249 | def __delitem__(self, key): | |||
|
250 | dict.__delitem__(self, key) | |||
|
251 | self._list.remove(key) | |||
|
252 | def keys(self): | |||
|
253 | return self._list | |||
|
254 | def iterkeys(self): | |||
|
255 | return self._list.__iter__() | |||
|
256 | ||||
226 | class lrucachedict(object): |
|
257 | class lrucachedict(object): | |
227 | '''cache most recent gets from or sets to this dictionary''' |
|
258 | '''cache most recent gets from or sets to this dictionary''' | |
228 | def __init__(self, maxsize): |
|
259 | def __init__(self, maxsize): |
General Comments 0
You need to be logged in to leave comments.
Login now