mirror of
https://github.com/gryf/wicd.git
synced 2026-01-31 04:55:52 +01:00
Don't allow no-value options in config files
This commit is contained in:
@@ -32,16 +32,26 @@ from wicd.misc import Noneify, to_unicode
|
|||||||
|
|
||||||
from dbus import Int32
|
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):
|
class ConfigManager(RawConfigParser):
|
||||||
""" A class that can be used to manage a given configuration file. """
|
""" A class that can be used to manage a given configuration file. """
|
||||||
def __init__(self, path, debug=False, mark_whitespace="`'`"):
|
def __init__(self, path, debug=False, mark_whitespace="`'`"):
|
||||||
if sys.version_info >= (2, 7, 0):
|
RawConfigParser.__init__(self)
|
||||||
RawConfigParser.__init__(self, allow_no_value=True)
|
|
||||||
else:
|
|
||||||
RawConfigParser.__init__(self)
|
|
||||||
self.config_file = path
|
self.config_file = path
|
||||||
self.debug = debug
|
self.debug = debug
|
||||||
self.mrk_ws = mark_whitespace
|
self.mrk_ws = mark_whitespace
|
||||||
|
if path:
|
||||||
|
sanitize_config_file(path)
|
||||||
try:
|
try:
|
||||||
self.read(path)
|
self.read(path)
|
||||||
except ParsingError, e:
|
except ParsingError, e:
|
||||||
|
|||||||
Reference in New Issue
Block a user