From 9613d98a439c53049a1850be31201c100575a7c0 Mon Sep 17 00:00:00 2001 From: sneakypete81 Date: Sat, 11 May 2013 18:17:21 +0100 Subject: [PATCH] Safer config defaults. Previously if the real config key was quoted, the default key might not be overridden. --- openphoto/openphoto_http.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/openphoto/openphoto_http.py b/openphoto/openphoto_http.py index 0657161..0e15802 100644 --- a/openphoto/openphoto_http.py +++ b/openphoto/openphoto_http.py @@ -253,11 +253,7 @@ class OpenPhotoHttp: 'token': '', 'tokenSecret':'', } # Insert an section header at the start of the config file, so ConfigParser can understand it - # Also prepend a [DEFAULT] section, since it's the only way to specify case-sensitive defaults buf = StringIO.StringIO() - buf.write("[DEFAULT]\n") - for key in defaults: - buf.write("%s=%s\n" % (key, defaults[key])) buf.write('[%s]\n' % section) buf.write(open(config_file).read()) @@ -270,4 +266,11 @@ class OpenPhotoHttp: config = parser.items(section) config = [(item[0].replace('"', ''), item[1].replace('"', '')) for item in config] config = [(item[0].replace("'", ""), item[1].replace("'", "")) for item in config] - return dict(config) + config = dict(config) + + # Apply defaults + for key in defaults: + if key not in config: + config[key] = defaults[key] + + return config