Show More
@@ -30,9 +30,11 b' class sortdict(dict):' | |||
|
30 | 30 | class config: |
|
31 | 31 | def __init__(self, data=None): |
|
32 | 32 | self._data = {} |
|
33 | self._source = {} | |
|
33 | 34 | if data: |
|
34 | 35 | for k in data._data: |
|
35 | 36 | self._data[k] = data[k].copy() |
|
37 | self._source = data._source.copy() | |
|
36 | 38 | def copy(self): |
|
37 | 39 | return config(self) |
|
38 | 40 | def __contains__(self, section): |
@@ -47,18 +49,20 b' class config:' | |||
|
47 | 49 | self._data[s] = sortdict() |
|
48 | 50 | for k in src._data[s]: |
|
49 | 51 | self._data[s][k] = src._data[s][k] |
|
52 | self._source[(s, k)] = src._source[(s, k)] | |
|
50 | 53 | def get(self, section, item, default=None): |
|
51 |
return self._data.get(section, {}).get(item, |
|
|
54 | return self._data.get(section, {}).get(item, default) | |
|
52 | 55 | def getsource(self, section, item): |
|
53 |
return self._ |
|
|
56 | return self._source.get((section, item), "") | |
|
54 | 57 | def sections(self): |
|
55 | 58 | return sorted(self._data.keys()) |
|
56 | 59 | def items(self, section): |
|
57 |
return |
|
|
60 | return self._data.get(section, {}).items() | |
|
58 | 61 | def set(self, section, item, value, source=""): |
|
59 | 62 | if section not in self: |
|
60 | 63 | self._data[section] = sortdict() |
|
61 |
self._data[section][item] = |
|
|
64 | self._data[section][item] = value | |
|
65 | self._source[(section, item)] = source | |
|
62 | 66 | |
|
63 | 67 | def read(self, path, fp=None): |
|
64 | 68 | sectionre = re.compile(r'\[([^\[]+)\]') |
General Comments 0
You need to be logged in to leave comments.
Login now