2 # Copyright (C) 2007 Marco Ferragina <marco.ferragina@gmail.com>
4 # This program is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation; either version 2 of the License, or
7 # (at your option) any later version.
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 from iniman
import IniMan
20 class NoSuchDictException(Exception): pass
21 class CannotSaveError(Exception): pass
22 class CorruptedConfiguration(Exception): pass
24 class DictHelper(IniMan
):
25 def __init__(self
, handler
):
26 IniMan
.__init
__(self
, handler
)
27 self
.__dicts
= self
.__retrieve
_dicts
()
29 def __retrieve_dicts(self
):
31 sections
= self
.get_sections()
33 dic
= self
.get_by_section(sec
)
40 self
.__dicts
= self
.__retrieve
_dicts
()
43 def remove_dict(self
, id):
45 for tmp
in self
.__dicts
:
49 raise NoSuchDictException
50 for key
, value
in dic
.iteritems():
51 self
.remove(id + "." + key
)
53 self
.__retrieve
_dicts
()
55 def add_dict(self
, dic
, force_id
= None):
57 sections
= self
.get_sections()
66 self
.__dicts
.append(dic
)
67 for key
, value
in dic
.iteritems():
68 self
.add(id + "." + key
, value
)
73 sections
= self
.get_sections()
75 self
.remove_dict(sect
)