From 758a2eb0182d27d181bf89a18cbb13194c9a9b17 Mon Sep 17 00:00:00 2001 From: s3lph Date: Fri, 13 Jul 2018 01:22:17 +0200 Subject: [PATCH] Fixed: Expand ~ in config file parsing. --- matemat/webserver/config.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/matemat/webserver/config.py b/matemat/webserver/config.py index c220adc..53386b5 100644 --- a/matemat/webserver/config.py +++ b/matemat/webserver/config.py @@ -1,6 +1,7 @@ from typing import Any, Dict +import os from configparser import ConfigParser @@ -30,14 +31,14 @@ def parse_config_file(path: str) -> Dict[str, Any]: # Replace the original option transformation by a string constructor to preserve the case of config keys parser.optionxform = str # Read the configuration file - parser.read(path, 'utf-8') + parser.read(os.path.expanduser(path), 'utf-8') # Read values from the [Matemat] section, if present, falling back to default values if 'Matemat' in parser.sections(): config['listen'] = parser['Matemat'].get('Address', config['listen']) config['port'] = int(parser['Matemat'].get('Port', config['port'])) - config['staticroot'] = parser['Matemat'].get('StaticPath', config['staticroot']) - config['templateroot'] = parser['Matemat'].get('TemplatePath', config['templateroot']) + config['staticroot'] = parser['Matemat'].get('StaticPath', os.path.expanduser(config['staticroot'])) + config['templateroot'] = parser['Matemat'].get('TemplatePath', os.path.expanduser(config['templateroot'])) # Read all values from the [Pagelets] section, if present. These values are passed to pagelet functions if 'Pagelets' in parser.sections():