From 0064f70160d869c78a2dfd216de09b4188e14203 Mon Sep 17 00:00:00 2001 From: "Dustin C. Hatch" Date: Sat, 5 Jan 2013 10:38:05 -0600 Subject: [PATCH] Update read_config for new API in Python 3.2 --HG-- branch : py3k --- src/milla/config.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/milla/config.py b/src/milla/config.py index f656411..f50790f 100644 --- a/src/milla/config.py +++ b/src/milla/config.py @@ -40,8 +40,14 @@ def read_config(filename): app.config.update(config) ''' - cparser = configparser.SafeConfigParser() - cparser.readfp(open(filename)) + with open(filename) as f: + # ConfigParser API changed in Python 3.2 + if hasattr(configparser.ConfigParser, 'read_file'): + cparser = configparser.ConfigParser() + cparser.read_file(f) + else: + cparser = configparser.SafeConfigParser() + cparser.readfp(f) config = {} for section in cparser.sections():