diff --git a/__init__.py b/__init__.py index 11b42d6..c35d81c 100644 --- a/__init__.py +++ b/__init__.py @@ -24,7 +24,7 @@ def create_app(): app = Flask( __name__, instance_relative_config=True, - static_folder=f"templates/{templatehelper.config['template']}/static") + static_folder=f"templates/{templatehelper.CONFIG['template']}/static") # paths sent by flask are relative to the "public" directory. This prefix should be added to # get paths relative to the pages root directory. pathprefix = '' @@ -56,7 +56,7 @@ def serve_directory(path): # Ensure paths always end with a "/" return flask.redirect('/' + path + '/') return flask.render_template( - os.path.join(templatehelper.config['template'], 'directory.html'), + os.path.join(templatehelper.CONFIG['template'], 'directory.html'), pathprefix = pathprefix, path = path, templatehelper = templatehelper) @@ -73,14 +73,14 @@ def serve_error(code, message=None): os.path.join( __name__, 'templates', - templatehelper.config['template'], + templatehelper.CONFIG['template'], f'{code}.html')): template = f'{code}.html' else: template = 'error.html' return flask.make_response(( flask.render_template( - os.path.join(templatehelper.config['template'], template), + os.path.join(templatehelper.CONFIG['template'], template), code=code, message=message, templatehelper=templatehelper, diff --git a/templatehelper.py b/templatehelper.py index b1e06ef..4d2a8a7 100644 --- a/templatehelper.py +++ b/templatehelper.py @@ -19,15 +19,15 @@ import regex import yaml -config = None -with open("../config.yaml") as file: - config = yaml.load(file, Loader=yaml.SafeLoader) +CONFIG = None +with open("../config.yaml", encoding='utf-8') as file: + CONFIG = yaml.load(file, Loader=yaml.SafeLoader) # paths sent by flask are relative to the "public" directory. This prefix should be added to get # paths relative to the pages root directory. #TODO: This is a redundant specification and should be avoided. -pathprefix = '' +PATHPREFIX = '' # List of official MIME Types: http://www.iana.org/assignments/media-types/media-types.xhtml # If you want additional mimetypes to be covered, add them to this list. @@ -71,12 +71,12 @@ def listdir(path): page and thus it will be ommited from the list as well. """ ignorelist = ['index', 'index.md', '*.scmsfasicon', '*.scmstarget'] - if os.path.exists(os.path.join(pathprefix, path, '.scmsignore')): - with open(os.path.join(pathprefix, path, '.scmsignore')) as file: + if os.path.exists(os.path.join(PATHPREFIX, path, '.scmsignore')): + with open(os.path.join(PATHPREFIX, path, '.scmsignore'), encoding='utf-8') as file: ignorelist.extend([line.strip('\n') for line in file.readlines()]) dirlist = [ os.path.basename(f) - for f in os.listdir(os.path.join(pathprefix, path)) + for f in os.listdir(os.path.join(PATHPREFIX, path)) if regex.match('^(?!\\.).*(?