use RawConfigParser instead of SafeConfigParser

This commit is contained in:
Romain Bignon 2010-08-14 17:45:31 +02:00
commit 074a1b871d

View file

@ -18,7 +18,7 @@
from __future__ import with_statement from __future__ import with_statement
from ConfigParser import SafeConfigParser from ConfigParser import RawConfigParser
import logging import logging
from logging import debug, error, exception, warning from logging import debug, error, exception, warning
import os import os
@ -112,10 +112,10 @@ class BackendsConfig(object):
u'Weboob will not start until config file %s is readable by group or other users.' % confpath) u'Weboob will not start until config file %s is readable by group or other users.' % confpath)
def iter_backends(self): def iter_backends(self):
config = SafeConfigParser() config = RawConfigParser()
config.read(self.confpath) config.read(self.confpath)
for instance_name in config.sections(): for instance_name in config.sections():
params = dict(config.items(instance_name, raw=True)) params = dict(config.items(instance_name))
try: try:
backend_name = params.pop('_backend') backend_name = params.pop('_backend')
except KeyError: except KeyError:
@ -131,7 +131,7 @@ class BackendsConfig(object):
def add_backend(self, instance_name, backend_name, params, edit=False): def add_backend(self, instance_name, backend_name, params, edit=False):
if not instance_name: if not instance_name:
raise ValueError(u'Please give a name to the configured backend.') raise ValueError(u'Please give a name to the configured backend.')
config = SafeConfigParser() config = RawConfigParser()
config.read(self.confpath) config.read(self.confpath)
if not edit: if not edit:
config.add_section(instance_name) config.add_section(instance_name)
@ -145,12 +145,12 @@ class BackendsConfig(object):
return self.add_backend(instance_name, backend_name, params, True) return self.add_backend(instance_name, backend_name, params, True)
def get_backend(self, instance_name): def get_backend(self, instance_name):
config = SafeConfigParser() config = RawConfigParser()
config.read(self.confpath) config.read(self.confpath)
if not config.has_section(instance_name): if not config.has_section(instance_name):
raise KeyError(u'Configured backend "%s" not found' % instance_name) raise KeyError(u'Configured backend "%s" not found' % instance_name)
items = dict(config.items(instance_name, raw=True)) items = dict(config.items(instance_name))
try: try:
backend_name = items.pop('_backend') backend_name = items.pop('_backend')
@ -164,7 +164,7 @@ class BackendsConfig(object):
return backend_name, items return backend_name, items
def remove_backend(self, instance_name): def remove_backend(self, instance_name):
config = SafeConfigParser() config = RawConfigParser()
config.read(self.confpath) config.read(self.confpath)
config.remove_section(instance_name) config.remove_section(instance_name)
with open(self.confpath, 'w') as f: with open(self.confpath, 'w') as f: