From 04d851ba79bddf193dfbad002133ae0b0f2a757a Mon Sep 17 00:00:00 2001 From: David Paleino Date: Wed, 9 Nov 2011 18:12:13 +0100 Subject: [PATCH] Don't allow no-value options in config files --- wicd/configmanager.py | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/wicd/configmanager.py b/wicd/configmanager.py index bf455ad..88ecb05 100644 --- a/wicd/configmanager.py +++ b/wicd/configmanager.py @@ -32,16 +32,26 @@ from wicd.misc import Noneify, to_unicode from dbus import Int32 +def sanitize_config_file(path): + conf = open(path) + newconf = '' + for line in conf: + if '[' not in line or '=' not in line: + newconf += line + conf.close() + conf = open(path, 'w') + conf.write(newconf) + conf.close() + class ConfigManager(RawConfigParser): """ A class that can be used to manage a given configuration file. """ def __init__(self, path, debug=False, mark_whitespace="`'`"): - if sys.version_info >= (2, 7, 0): - RawConfigParser.__init__(self, allow_no_value=True) - else: - RawConfigParser.__init__(self) + RawConfigParser.__init__(self) self.config_file = path self.debug = debug self.mrk_ws = mark_whitespace + if path: + sanitize_config_file(path) try: self.read(path) except ParsingError, e: