mirror of
https://github.com/tahoe-lafs/tahoe-lafs.git
synced 2025-04-07 10:56:49 +00:00
Create ConfigParsers in a consistent manner.
This commit is contained in:
parent
207111fb9c
commit
0d270e1290
@ -184,12 +184,13 @@ def read_config(basedir, portnumfile, generated_files=[], _valid_config=None):
|
||||
|
||||
# (try to) read the main config file
|
||||
config_fname = os.path.join(basedir, "tahoe.cfg")
|
||||
parser = configparser.ConfigParser()
|
||||
try:
|
||||
parser = configutil.get_config(config_fname)
|
||||
except EnvironmentError as e:
|
||||
if e.errno != errno.ENOENT:
|
||||
raise
|
||||
# The file is missing, just create empty ConfigParser.
|
||||
parser = configutil.create_parser()
|
||||
|
||||
configutil.validate_config(config_fname, parser, _valid_config)
|
||||
|
||||
@ -207,7 +208,7 @@ def config_from_string(basedir, portnumfile, config_str, _valid_config=None):
|
||||
_valid_config = _common_valid_config()
|
||||
|
||||
# load configuration from in-memory string
|
||||
parser = configparser.ConfigParser()
|
||||
parser = configutil.create_parser()
|
||||
if isinstance(config_str, bytes):
|
||||
config_str = config_str.decode("utf-8")
|
||||
parser.read_string(config_str)
|
||||
|
@ -29,12 +29,20 @@ class UnknownConfigError(Exception):
|
||||
"""
|
||||
|
||||
|
||||
def create_parser():
|
||||
"""
|
||||
Create a ConfigParser pre-configured the way we want it, for consistency
|
||||
across different code paths.
|
||||
"""
|
||||
return ConfigParser(strict=False)
|
||||
|
||||
|
||||
def get_config(tahoe_cfg):
|
||||
"""Load the config, returning a ConfigParser.
|
||||
|
||||
Configuration is returned as Unicode strings.
|
||||
"""
|
||||
config = ConfigParser(strict=False)
|
||||
config = create_parser()
|
||||
# Byte Order Mark is an optional garbage code point you sometimes get at
|
||||
# the start of UTF-8 encoded files. Especially on Windows. Skip it by using
|
||||
# utf-8-sig. https://en.wikipedia.org/wiki/Byte_order_mark
|
||||
|
Loading…
x
Reference in New Issue
Block a user