Add a `defaults` keyword to `milla.util.read_config`

master
Dustin C. Hatch 2013-01-20 14:49:24 -06:00
parent 65ebf76b45
commit 9da12232d4
1 changed files with 3 additions and 3 deletions

View File

@ -68,7 +68,7 @@ def http_date(date):
return format_date_time(stamp) return format_date_time(stamp)
def read_config(filename): def read_config(filename, defaults=None):
'''Parse an ini file into a nested dictionary '''Parse an ini file into a nested dictionary
:param string filename: Path to the ini file to read :param string filename: Path to the ini file to read
@ -108,10 +108,10 @@ def read_config(filename):
with open(filename) as f: with open(filename) as f:
# ConfigParser API changed in Python 3.2 # ConfigParser API changed in Python 3.2
if hasattr(configparser.ConfigParser, 'read_file'): if hasattr(configparser.ConfigParser, 'read_file'):
cparser = configparser.ConfigParser() cparser = configparser.ConfigParser(defaults)
cparser.read_file(f) cparser.read_file(f)
else: else:
cparser = configparser.SafeConfigParser() cparser = configparser.SafeConfigParser(defaults)
cparser.readfp(f) cparser.readfp(f)
config = {} config = {}