From d7d9f12cd980b9de9e550bab0e9af8a4625f0591 Mon Sep 17 00:00:00 2001 From: kamikazekuh <33634496+kamikazekuh@users.noreply.github.com> Date: Fri, 14 Sep 2018 18:45:53 +0200 Subject: [PATCH] added encoding property to the ConfigManager --- .../packages/source-python/config/manager.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/addons/source-python/packages/source-python/config/manager.py b/addons/source-python/packages/source-python/config/manager.py index cd6613597..243819e0f 100644 --- a/addons/source-python/packages/source-python/config/manager.py +++ b/addons/source-python/packages/source-python/config/manager.py @@ -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: @@ -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 = '' @@ -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) @@ -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(): @@ -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()]