[go: up one dir, main page]

Skip to content

Commit

Permalink
Forcing the use of UTF-8 for file I/O to fix errors on Centos 7
Browse files Browse the repository at this point in the history
  • Loading branch information
joosthooz committed Jul 16, 2021
1 parent f166b07 commit aeadf9f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions vhdmmio/configurable/configurable.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ def load(cls, obj, parent=None):
if isinstance(obj, str):
if obj.lower().endswith('.json'):
loader = json.loads
with open(obj, 'r') as fil:
with open(obj, 'r', encoding="utf-8") as fil:
return cls(
parent, loader(fil.read()),
source_file=obj)
Expand Down Expand Up @@ -148,7 +148,7 @@ def save(self, obj=None):
data = dumper(data, default_flow_style=False)

if isinstance(obj, str):
with open(obj, 'w') as fil:
with open(obj, 'w', encoding="utf-8") as fil:
fil.write(data)
return None

Expand Down
8 changes: 4 additions & 4 deletions vhdmmio/template.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,22 +133,22 @@ def apply_file_to_file(self, template_filename, output_filename, *args, **kwargs
result to the given output file. Extra arguments are passed to
`apply_str_to_str()` and are documented there."""
output = self.apply_file_to_str(template_filename, *args, **kwargs)
with open(output_filename, 'w') as output_file:
with open(output_filename, 'w', encoding="utf-8") as output_file:
output_file.write(output)

def apply_str_to_file(self, template, output_filename, *args, **kwargs):
"""Applies this template engine to the given template string, writing the
result to the given output file. Extra arguments are passed to
`apply_str_to_str()` and are documented there."""
output = self.apply_str_to_str(template, *args, **kwargs)
with open(output_filename, 'w') as output_file:
with open(output_filename, 'w', encoding="utf-8") as output_file:
output_file.write(output)

def apply_file_to_str(self, template_filename, *args, **kwargs):
"""Applies this template engine to the given template file, returning
the result as a string. Extra arguments are passed to
`apply_str_to_str()` and are documented there."""
with open(template_filename, 'r') as template_file:
with open(template_filename, 'r', encoding="utf-8") as template_file:
template = annotate_block(
template_file.read(),
template_filename,
Expand Down Expand Up @@ -784,7 +784,7 @@ def preload_template(fname, comment='#'):
caller_fname, _, _, _, _ = inspect.getframeinfo(previous_frame)
fname = os.path.dirname(caller_fname) + os.sep + fname

with open(fname, 'r') as fil:
with open(fname, 'r', encoding="utf-8") as fil:
template = fil.read()

return annotate_block(template, fname, comment)

0 comments on commit aeadf9f

Please sign in to comment.