1 # -*- encoding: utf-8 -*-
2 # Copyright P. Christeas <p_christ@hol.gr> 2008-2010
3 # Copyright 2010 OpenERP SA. http://www.openerp.com
5 # This program is Free Software; you can redistribute it and/or
6 # modify it under the terms of the GNU Lesser General Public License
7 # as published by the Free Software Foundation; version 2 of the License.
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 Lesser 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 ###############################################################################
20 def dict_merge(*dicts):
21 """ Return a dict with all values of dicts
28 def dict_merge2(*dicts):
29 """ Return a dict with all values of dicts.
30 If some key appears twice and contains iterable objects, the values
31 are merged (instead of overwritten).
36 if k in res and isinstance(res[k], (list, tuple)):
37 res[k] = res[k] + d[k]
38 elif k in res and isinstance(res[k], dict):
44 def dict_filter(srcdic, keys, res=None):
45 ''' Return a copy of srcdic that has only keys set.
46 If any of keys are missing from srcdic, the result won't have them,
48 @param res If given, result will be updated there, instead of a new dict.