comparison mercurial/config.py @ 8186:6a0018cdb2fe

config: add some helper methods
author Matt Mackall <mpm@selenic.com>
date Sun, 26 Apr 2009 16:50:43 -0500
parents dc10a7a3f1d4
children d2504744e7a5
comparison
equal deleted inserted replaced
8185:dc10a7a3f1d4 8186:6a0018cdb2fe
25 return [(k,self[k]) for k in self._list] 25 return [(k,self[k]) for k in self._list]
26 def __delitem__(self, key): 26 def __delitem__(self, key):
27 dict.__delitem__(self, key) 27 dict.__delitem__(self, key)
28 self._list.remove(key) 28 self._list.remove(key)
29 29
30 class config: 30 class config(object):
31 def __init__(self, data=None): 31 def __init__(self, data=None):
32 self._data = {} 32 self._data = {}
33 self._source = {} 33 self._source = {}
34 if data: 34 if data:
35 for k in data._data: 35 for k in data._data:
37 self._source = data._source.copy() 37 self._source = data._source.copy()
38 def copy(self): 38 def copy(self):
39 return config(self) 39 return config(self)
40 def __contains__(self, section): 40 def __contains__(self, section):
41 return section in self._data 41 return section in self._data
42 def __getitem__(self, section):
43 return self._data.get(section, {})
44 def __iter__(self):
45 for d in self.sections():
46 yield d
42 def update(self, src, sections=None): 47 def update(self, src, sections=None):
43 if not sections: 48 if not sections:
44 sections = src.sections() 49 sections = src.sections()
45 for s in sections: 50 for s in sections:
46 if s not in src: 51 if s not in src: