Skip to content

Commit f1b3250

Browse files
authored
fix(io): explicitly declare UTF-8 encoding in IO operations (#520)
2 parents 18a44bf + 016e8e6 commit f1b3250

File tree

5 files changed

+8
-8
lines changed

5 files changed

+8
-8
lines changed

qgis_deployment_toolbelt/plugins/plugin.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ def from_plugin_folder(cls, input_plugin_folder: Path) -> QgisPlugin:
151151
)
152152

153153
# read it
154-
with plugin_metadata_txt.open() as config_file:
154+
with plugin_metadata_txt.open(encoding="UTF-8") as config_file:
155155
config = configparser.ConfigParser(strict=False)
156156
config.read_file(config_file)
157157
plugin_md_as_dict = {k: v for k, v in config.items(section="general")}
@@ -181,7 +181,7 @@ def from_zip(cls, input_zip_path: Path) -> QgisPlugin:
181181
zip_path = zipfile.Path(zf)
182182
metadata_file = zip_path / i.filename
183183
plugin_folder_name = metadata_file.parent.name
184-
with metadata_file.open() as config_file:
184+
with metadata_file.open(encoding="UTF-8") as config_file:
185185
config = configparser.ConfigParser(strict=False)
186186
config.read_file(config_file)
187187

qgis_deployment_toolbelt/profiles/qgis_ini_handler.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -627,10 +627,10 @@ def merge_to(self, dst: QgisIniHelper) -> None:
627627
self._backup_section(config_dest, config_src, section, dst.ini_filepath)
628628
self._copy_section(config_dest, config_src, section)
629629
# Write to destination, environnement variable will be interpolated if interpolation enabled
630-
with dst.ini_filepath.open("w") as config_file:
630+
with dst.ini_filepath.open(mode="w", encoding="UTF-8") as config_file:
631631
config_dest.write(config_file)
632632
else:
633-
with dst.ini_filepath.open("w") as config_file:
633+
with dst.ini_filepath.open(mode="w", encoding="UTF-8") as config_file:
634634
config_src.write(config_file)
635635

636636

qgis_deployment_toolbelt/scenarios/scenario_reader.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def __init__(self, in_yaml: str | Path | BufferedIOBase):
4646
if isinstance(in_yaml, (str, Path)):
4747
self.input_yaml = self.check_yaml_file(in_yaml)
4848
# extract data from input file
49-
with self.input_yaml.open(mode="r") as bytes_data:
49+
with self.input_yaml.open(mode="r", encoding="UTF-8") as bytes_data:
5050
self.scenario = yaml.safe_load(bytes_data)
5151
elif isinstance(in_yaml, BufferedIOBase):
5252
self.input_yaml = self.check_yaml_buffer(in_yaml)
@@ -74,7 +74,7 @@ def check_yaml_file(self, yaml_path: str | Path) -> Path:
7474
yaml_path = Path(yaml_path)
7575

7676
# check integrity and structure
77-
with yaml_path.open(mode="r") as in_yaml_file:
77+
with yaml_path.open(mode="r", encoding="UTF-8") as in_yaml_file:
7878
try:
7979
yaml.safe_load_all(in_yaml_file)
8080
except yaml.YAMLError as exc:

qgis_deployment_toolbelt/shortcuts/shortcuts.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ def desktop_path(self) -> Path:
263263
raise_error=False,
264264
)
265265
if is_config_file_usable:
266-
with config_xdg_user_dirs.open("r") as bf_config:
266+
with config_xdg_user_dirs.open(mode="r", encoding="UTF-8") as bf_config:
267267
data = bf_config.read()
268268

269269
desktop_paths = re.findall('XDG_DESKTOP_DIR="([^"]*)', data)

qgis_deployment_toolbelt/utils/linux_utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ def set_environment_variable(
209209
f"{export_line}\n",
210210
f"{qdt_block_comment_end}",
211211
)
212-
with open(profile_file, "a") as file:
212+
with profile_file.open(mode="a", encoding="UTF-8") as file:
213213
file.writelines(new_lines)
214214
logger.info(
215215
f"Nor QDT block and the line: '{export_line}' were present. "

0 commit comments

Comments
 (0)