+
+def _set_default_config(parser, values):
+ """
+ Saves the values given to the ConfigParser given. This can be used
+ to store a set of default values to a ConfigParser before loading a
+ file (The defaults argument to the ConfigParser constructor only
+ sets the values of the "DEFAULT" section).
+
+ The values argument contains a dictionary of sections. Each key is a
+ section name, each value is a dictionary of values (where the key is
+ the value name and the value is the actual value).
+ """
+ for section, options in values.items():
+ if not parser.has_section(section):
+ parser.add_section(section)
+ for option, value in options.items():
+ # Interpret None as "no default", since ConfigParser doesn't
+ # like non-string values.
+ if not value is None:
+ parser.set(section, option, value)