diff --git a/cache.py b/cache.py
index 950bec9..fa92ca0 100644
--- a/cache.py
+++ b/cache.py
@@ -47,12 +47,12 @@ def not_cached_before(root, lang, file):
# Restore the cached chapter.
def get_cached_chapter(root, lang, chapter):
chapter_path = os.path.join(root, '.onpoint', lang, chapter + '.cache')
- return open(chapter_path, 'r').read()
+ return open(chapter_path, 'r', encoding='utf8').read()
# Store a cached version of a chapter.
def store_cached_chapter(root, lang, chapter, content):
chapter_path = os.path.join(root, '.onpoint', lang, chapter + '.cache')
- chapter_file = open(chapter_path, 'w')
+ chapter_file = open(chapter_path, 'w', encoding='utf-8')
chapter_file.write(content)
chapter_file.close()
@@ -66,12 +66,12 @@ def __init_cache_directory(root, lang):
# Save the current time to the timestamp file.
def save_compile_timestamp(root, lang, file_name=timestamp_file_name):
timestamp_file_path = os.path.join(root, '.onpoint', lang, file_name)
- timestamp_file = open(timestamp_file_path, 'w')
+ timestamp_file = open(timestamp_file_path, 'w', encoding='utf-8')
timestamp_file.write(str(int(time.time())))
timestamp_file.close()
# Retrieve the compile timestamp.
def __get_last_compile_time(root, lang):
timestamp_file_path = os.path.join(root, '.onpoint', lang, timestamp_file_name)
- with open(timestamp_file_path) as f:
+ with open(timestamp_file_path, encoding='utf8') as f:
return int(f.readline())
diff --git a/chapters.py b/chapters.py
index f02f27e..4afed56 100644
--- a/chapters.py
+++ b/chapters.py
@@ -21,7 +21,7 @@ def compile_chapters(root_directory, language, force_recompile=False):
chapters = ""
for chapter in structure:
- chapters += '\n' + compile_chapter(chapter, no_cache) + '\n'
+ chapters += '' + os.linesep + compile_chapter(chapter, no_cache) + os.linesep + ''
cache.save_compile_timestamp(root, lang)
return chapters # string
@@ -47,7 +47,7 @@ def compile_chapter(chapter, no_cache):
return cache.get_cached_chapter(root, lang, chapter)
print("Recompiling chapter " + chapter + " (" + lang + ").")
- chapter_file = open(chapter_path, 'r')
+ chapter_file = open(chapter_path, 'r', encoding='utf-8')
delimiter = '\n@slide'
chapter_input = ('\n' + chapter_file.read()).split(delimiter)
slides = [delimiter + slide for slide in chapter_input][1:]
diff --git a/helper.py b/helper.py
index bf70e20..f0db7bf 100644
--- a/helper.py
+++ b/helper.py
@@ -6,7 +6,7 @@ import re
# Calls a YAML parser for the given relative path inside the presentation root
# directory. Returns a dictionary with the YAML content.
def read_yaml(root, path):
- with open(os.path.join(root, path), 'r') as stream:
+ with open(os.path.join(root, path), 'r', encoding='utf8') as stream:
try:
return yaml.safe_load(stream)
except yaml.YAMLError as exc:
@@ -47,7 +47,7 @@ def add_lazyload(source, lazyload_images):
# per presentation.
def add_help_menu(source, root):
help_menu_code = open(os.path.join(
- root, 'onpoint/help-menu.html'), "r").read()
+ root, 'onpoint/help-menu.html'), 'r', encoding='utf8').read()
help_menu_code = re.sub('@imprint', read_yaml(root, 'legal.yml')['imprint'], help_menu_code)
help_menu_code = re.sub('@privacy-policy', read_yaml(root, 'legal.yml')['privacy-policy'], help_menu_code)
return re.sub('@help', help_menu_code, source)
diff --git a/main.py b/main.py
index 5b2389c..5524c04 100755
--- a/main.py
+++ b/main.py
@@ -13,14 +13,14 @@ import helper
def compile(root, language='en', force_recompile=False, lazyload_images=False):
- wrapper = open(os.path.join(root, 'layouts/root.html'), 'r').read()
+ wrapper = open(os.path.join(root, 'layouts/root.html'), 'r', encoding='utf8').read()
compiled_chapters = chapters.compile_chapters(root, language, force_recompile)
wrapper = wrapper.replace('@slides', compiled_chapters)
wrapper = helper.insert_metadata(wrapper, root, language)
wrapper = fragments.defragmentize(wrapper)
wrapper = helper.add_lazyload(wrapper, lazyload_images)
wrapper = helper.add_help_menu(wrapper, root)
- with open(os.path.join(root, 'slides.' + language + '.html'), 'w+') as output:
+ with open(os.path.join(root, 'slides.' + language + '.html'), 'w+', encoding='utf8') as output:
output.write(wrapper)
print('done')
diff --git a/slides.py b/slides.py
index b031cf7..c735e89 100644
--- a/slides.py
+++ b/slides.py
@@ -53,7 +53,7 @@ def get_slide_data(slide):
def get_slide_layout(layout_name):
global root
try:
- return open(os.path.join(root, 'layouts/' + layout_name + '.html'), 'r').read()
+ return open(os.path.join(root, 'layouts/' + layout_name + '.html'), 'r', encoding='utf8').read()
except FileNotFoundError:
raise Exception('Layout ' + layout_name + ' not found!')