Change the official config filename to config.yml. Interpret ALLOWED_HOSTS as YAML.

Signed-off-by: Roberto Rosario <roberto.rosario.gonzalez@gmail.com>
This commit is contained in:
Roberto Rosario
2018-08-26 05:10:33 -04:00
parent 040c99d809
commit 4a61275e80
3 changed files with 56 additions and 41 deletions
+40
View File
@@ -0,0 +1,40 @@
from __future__ import unicode_literals
import errno
import os
import sys
import yaml
def read_configuration_file(path):
try:
with open(path) as file_object:
file_object.seek(0, os.SEEK_END)
if file_object.tell():
file_object.seek(0)
try:
return yaml.safe_load(file_object)
except yaml.YAMLError as exception:
exit(
'Error loading configuration file: {}; {}'.format(
path, exception
)
)
except IOError as exception:
if exception.errno == errno.ENOENT:
pass
else:
raise
def yaml_loads(data, error_message=None):
if not error_message:
error_message = 'Error loading: {}; {}'
try:
return yaml.safe_load(data)
except yaml.YAMLError as exception:
exit(
error_message.format(string, exception)
)