Skip to content

added encoding property to the ConfigManager #257

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 15, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions addons/source-python/packages/source-python/config/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class ConfigManager(object):
"""Config Management class used to create a config file."""

def __init__(
self, filepath, cvar_prefix='', indention=3, max_line_length=79):
self, filepath, cvar_prefix='', indention=3, max_line_length=79, encoding='utf-8'):
"""Initialized the configuration manager.

:param str filepath:
Expand All @@ -75,6 +75,7 @@ def __init__(
self._cvar_prefix = cvar_prefix
self._indention = indention
self._max_line_length = max_line_length
self._encoding = encoding

# Store the header and separator
self.header = ''
Expand Down Expand Up @@ -263,7 +264,7 @@ def write(self):
self.fullpath.parent.makedirs()

# Open/close the file to write to it
with self.fullpath.open('w') as open_file:
with self.fullpath.open('w', encoding=self._encoding) as open_file:

# Get the number of spaces to indent after //
spaces = ' ' * (self.indention - 2)
Expand Down Expand Up @@ -329,7 +330,7 @@ def execute(self):
self.fullpath))

# Open/close the file
with self.fullpath.open() as open_file:
with self.fullpath.open(encoding=self._encoding) as open_file:

# Loop through all lines in the file
for line in open_file.readlines():
Expand Down Expand Up @@ -385,7 +386,7 @@ def _parse_old_file(self):
return _old_config

# Open/close the file
with self.fullpath.open() as open_file:
with self.fullpath.open(encoding=self._encoding) as open_file:

# Get all lines from the file
_all_lines = [line.strip() for line in open_file.readlines()]
Expand Down