Skip to content

Commit

Permalink
fix(io): explicitly declare UTF-8 encoding in IO operations (#520)
Browse files Browse the repository at this point in the history
  • Loading branch information
Guts authored Jun 6, 2024
2 parents 18a44bf + 016e8e6 commit f1b3250
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 8 deletions.
4 changes: 2 additions & 2 deletions qgis_deployment_toolbelt/plugins/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ def from_plugin_folder(cls, input_plugin_folder: Path) -> QgisPlugin:
)

# read it
with plugin_metadata_txt.open() as config_file:
with plugin_metadata_txt.open(encoding="UTF-8") as config_file:
config = configparser.ConfigParser(strict=False)
config.read_file(config_file)
plugin_md_as_dict = {k: v for k, v in config.items(section="general")}
Expand Down Expand Up @@ -181,7 +181,7 @@ def from_zip(cls, input_zip_path: Path) -> QgisPlugin:
zip_path = zipfile.Path(zf)
metadata_file = zip_path / i.filename
plugin_folder_name = metadata_file.parent.name
with metadata_file.open() as config_file:
with metadata_file.open(encoding="UTF-8") as config_file:
config = configparser.ConfigParser(strict=False)
config.read_file(config_file)

Expand Down
4 changes: 2 additions & 2 deletions qgis_deployment_toolbelt/profiles/qgis_ini_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -627,10 +627,10 @@ def merge_to(self, dst: QgisIniHelper) -> None:
self._backup_section(config_dest, config_src, section, dst.ini_filepath)
self._copy_section(config_dest, config_src, section)
# Write to destination, environnement variable will be interpolated if interpolation enabled
with dst.ini_filepath.open("w") as config_file:
with dst.ini_filepath.open(mode="w", encoding="UTF-8") as config_file:
config_dest.write(config_file)
else:
with dst.ini_filepath.open("w") as config_file:
with dst.ini_filepath.open(mode="w", encoding="UTF-8") as config_file:
config_src.write(config_file)


Expand Down
4 changes: 2 additions & 2 deletions qgis_deployment_toolbelt/scenarios/scenario_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def __init__(self, in_yaml: str | Path | BufferedIOBase):
if isinstance(in_yaml, (str, Path)):
self.input_yaml = self.check_yaml_file(in_yaml)
# extract data from input file
with self.input_yaml.open(mode="r") as bytes_data:
with self.input_yaml.open(mode="r", encoding="UTF-8") as bytes_data:
self.scenario = yaml.safe_load(bytes_data)
elif isinstance(in_yaml, BufferedIOBase):
self.input_yaml = self.check_yaml_buffer(in_yaml)
Expand Down Expand Up @@ -74,7 +74,7 @@ def check_yaml_file(self, yaml_path: str | Path) -> Path:
yaml_path = Path(yaml_path)

# check integrity and structure
with yaml_path.open(mode="r") as in_yaml_file:
with yaml_path.open(mode="r", encoding="UTF-8") as in_yaml_file:
try:
yaml.safe_load_all(in_yaml_file)
except yaml.YAMLError as exc:
Expand Down
2 changes: 1 addition & 1 deletion qgis_deployment_toolbelt/shortcuts/shortcuts.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ def desktop_path(self) -> Path:
raise_error=False,
)
if is_config_file_usable:
with config_xdg_user_dirs.open("r") as bf_config:
with config_xdg_user_dirs.open(mode="r", encoding="UTF-8") as bf_config:
data = bf_config.read()

desktop_paths = re.findall('XDG_DESKTOP_DIR="([^"]*)', data)
Expand Down
2 changes: 1 addition & 1 deletion qgis_deployment_toolbelt/utils/linux_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ def set_environment_variable(
f"{export_line}\n",
f"{qdt_block_comment_end}",
)
with open(profile_file, "a") as file:
with profile_file.open(mode="a", encoding="UTF-8") as file:
file.writelines(new_lines)
logger.info(
f"Nor QDT block and the line: '{export_line}' were present. "
Expand Down

0 comments on commit f1b3250

Please sign in to comment.