Skip to content

Commit

Permalink
Pass encoding='utf-8' when opening text files
Browse files Browse the repository at this point in the history
  • Loading branch information
manisandro committed Dec 21, 2023
1 parent faefa55 commit 6120b25
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 8 deletions.
10 changes: 5 additions & 5 deletions src/config_generator/config_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ def __init__(self, config, logger, config_file_dir):
if not os.path.isabs(config_template_path):
config_template_path = os.path.join(config_file_dir, config_template_path)
try:
with open(config_template_path, 'r') as fh:
with open(config_template_path, 'r', encoding='utf-8') as fh:
config_template_data = fh.read().replace('$tenant$', self.tenant)
config_template = json.loads(config_template_data, object_pairs_hook=OrderedDict)

Expand Down Expand Up @@ -204,7 +204,7 @@ def __init__(self, config, logger, config_file_dir):
try:
if not os.path.isabs(themes_config):
themes_config = os.path.join(config_file_dir, themes_config)
with open(themes_config) as f:
with open(themes_config, encoding='utf-8') as f:
themes_config = json.load(f)
except:
msg = "Failed to read themes configuration %s" % themes_config
Expand Down Expand Up @@ -243,7 +243,7 @@ def __init__(self, config, logger, config_file_dir):
'schema-versions.json'
)
try:
with open(schema_versions_path) as f:
with open(schema_versions_path, encoding='utf-8') as f:
schema_versions = json.load(f)
except Exception as e:
msg = (
Expand Down Expand Up @@ -522,7 +522,7 @@ def validate_schema(self, config, schema_url):
# parse schema URL
file_name = os.path.basename(urlparse(schema_url).path)
file_path = os.path.join(self.json_schemas_path, file_name)
with open(file_path) as f:
with open(file_path, encoding='utf-8') as f:
schema = json.load(f)
except Exception as e:
self.logger.warning(
Expand Down Expand Up @@ -751,7 +751,7 @@ def search_print_layouts(self, generator_config):
continue

path = os.path.join(qgis_print_layouts_dir, dirpath, filename)
with open(path) as fh:
with open(path, encoding='utf-8') as fh:
doc = ElementTree.parse(fh)

layout = doc.getroot()
Expand Down
2 changes: 1 addition & 1 deletion src/config_generator/map_viewer_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -916,7 +916,7 @@ def copy_index_html(self):
# read index.html
index_file = cfg_qwc2_config.get('qwc2_index_file', 'index.html')
index_contents = None
with open(index_file) as f:
with open(index_file, encoding='utf-8') as f:
index_contents = f.read()

# write to tenant dir
Expand Down
2 changes: 1 addition & 1 deletion src/config_generator_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def timestamp(self):

# read ConfigGenerator config file
try:
with open(args.config_file) as f:
with open(args.config_file, encoding='utf-8') as f:
# parse config JSON with original order of keys
config = json.load(f, object_pairs_hook=OrderedDict)
except Exception as e:
Expand Down
2 changes: 1 addition & 1 deletion src/download_json_schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
f'schemas/schema-versions.json'
)
try:
with open(schema_versions_path) as f:
with open(schema_versions_path, encoding='utf-8') as f:
schema_versions = json.load(f)
except Exception as e:
print(
Expand Down

0 comments on commit 6120b25

Please sign in to comment.