diff --git a/map_machine/drawing.py b/map_machine/drawing.py index 27976d1..cfec7dc 100644 --- a/map_machine/drawing.py +++ b/map_machine/drawing.py @@ -140,7 +140,7 @@ class SVGDrawing(Drawing): def write(self) -> None: """Write image to the SVG file.""" - with self.file_path.open("w+") as output_file: + with self.file_path.open("w+", encoding="utf-8") as output_file: self.image.write(output_file) diff --git a/map_machine/element.py b/map_machine/element.py index d68d944..0f399bd 100644 --- a/map_machine/element.py +++ b/map_machine/element.py @@ -69,6 +69,6 @@ def draw_element(options: argparse.Namespace) -> None: point.draw_main_shapes(svg) point.draw_extra_shapes(svg) point.draw_texts(svg) - with output_file_path.open("w+") as output_file: + with output_file_path.open("w+", encoding="utf-8") as output_file: svg.write(output_file) logging.info(f"Element is written to {output_file_path}.") diff --git a/map_machine/grid.py b/map_machine/grid.py index 57431f6..8b9e1c1 100644 --- a/map_machine/grid.py +++ b/map_machine/grid.py @@ -196,7 +196,7 @@ class IconCollection: point += np.array((0, step)) height += step - with file_name.open("w") as output_file: + with file_name.open("w", encoding="utf-8") as output_file: svg.write(output_file) def __len__(self) -> int: diff --git a/map_machine/icon.py b/map_machine/icon.py index 168520d..bd9a9b6 100644 --- a/map_machine/icon.py +++ b/map_machine/icon.py @@ -404,7 +404,7 @@ class Icon: shape_specification.color = color shape_specification.draw(svg, np.array((8, 8))) - with file_name.open("w") as output_file: + with file_name.open("w", encoding="utf-8") as output_file: svg.write(output_file) def is_default(self) -> bool: diff --git a/map_machine/mapcss.py b/map_machine/mapcss.py index 371748d..71317b3 100644 --- a/map_machine/mapcss.py +++ b/map_machine/mapcss.py @@ -199,7 +199,9 @@ def ui(options: argparse.Namespace) -> None: options.ways, options.lifecycle, ) - with workspace.get_mapcss_file_path().open("w+") as output_file: + with workspace.get_mapcss_file_path().open( + "w+", encoding="utf-8" + ) as output_file: mapcss_writer.write(output_file) logging.info(f"MapCSS 0.2 scheme is written to {directory}.") diff --git a/map_machine/moire_manager.py b/map_machine/moire_manager.py index 23e9853..4de1937 100644 --- a/map_machine/moire_manager.py +++ b/map_machine/moire_manager.py @@ -307,8 +307,8 @@ class MapMachineMarkdown(MapMachineMoire, DefaultMarkdown): def convert(input_path: Path, output_path: Path) -> None: """Convert Moire file to Markdown.""" - with input_path.open() as input_file: - with output_path.open("w+") as output_file: + with input_path.open(encoding="utf-8") as input_file: + with output_path.open("w+", encoding="utf-8") as output_file: output_file.write(MapMachineMarkdown().convert(input_file.read())) diff --git a/map_machine/osm_reader.py b/map_machine/osm_reader.py index 80c8f94..6315cbe 100644 --- a/map_machine/osm_reader.py +++ b/map_machine/osm_reader.py @@ -361,7 +361,7 @@ class OSMData: See https://wiki.openstreetmap.org/wiki/Overpass_API """ - with file_name.open() as input_file: + with file_name.open(encoding="utf-8") as input_file: structure = json.load(input_file) node_map: dict[int, OSMNode] = {} diff --git a/map_machine/scheme.py b/map_machine/scheme.py index 1632841..76a1178 100644 --- a/map_machine/scheme.py +++ b/map_machine/scheme.py @@ -306,7 +306,7 @@ class Scheme: :param file_name: name of the scheme file with tags, colors, and tag key specification """ - with file_name.open() as input_file: + with file_name.open(encoding="utf-8") as input_file: content: dict[str, Any] = yaml.load( input_file.read(), Loader=yaml.FullLoader ) diff --git a/map_machine/server.py b/map_machine/server.py index ad0d3f3..ee747a0 100644 --- a/map_machine/server.py +++ b/map_machine/server.py @@ -51,7 +51,7 @@ class _Handler(SimpleHTTPRequestHandler): if not png_path.exists(): if not svg_path.exists(): tile.draw(tile_path, self.cache, self.options) - with svg_path.open() as input_file: + with svg_path.open(encoding="utf-8") as input_file: cairosvg.svg2png( file_obj=input_file, write_to=str(png_path) ) diff --git a/map_machine/taginfo.py b/map_machine/taginfo.py index 94c0cd2..9ad2592 100644 --- a/map_machine/taginfo.py +++ b/map_machine/taginfo.py @@ -73,7 +73,7 @@ class TaginfoProjectFile: def write(self) -> None: """Write Taginfo JSON file.""" - with self.path.open("w+") as output_file: + with self.path.open("w+", encoding="utf-8") as output_file: json.dump(self.structure, output_file, indent=4, sort_keys=True) diff --git a/map_machine/tile.py b/map_machine/tile.py index 4ac46a8..77593ad 100644 --- a/map_machine/tile.py +++ b/map_machine/tile.py @@ -182,12 +182,12 @@ class Tile: ) painter.draw(constructor) - with output_file_name.open("w") as output_file: + with output_file_name.open("w", encoding="utf-8") as output_file: svg.write(output_file) logging.info(f"Tile is drawn to {output_file_name}.") output_path: Path = output_file_name.with_suffix(".png") - with output_file_name.open() as input_file: + with output_file_name.open(encoding="utf-8") as input_file: cairosvg.svg2png(file_obj=input_file, write_to=str(output_path)) logging.info(f"SVG file is rasterized to {output_path}.") @@ -287,7 +287,7 @@ class Tiles: output_path: Path = file_path.with_suffix(".png") if not output_path.exists(): - with file_path.open() as input_file: + with file_path.open(encoding="utf-8") as input_file: cairosvg.svg2png( file_obj=input_file, write_to=str(output_path) ) @@ -398,14 +398,14 @@ class Tiles: map_.draw(constructor) logging.info(f"Writing output SVG {output_path}...") - with output_path.open("w+") as output_file: + with output_path.open("w+", encoding="utf-8") as output_file: svg.write(output_file) else: logging.debug(f"File {output_path} already exists.") png_path: Path = self.get_file_path(cache_path).with_suffix(".png") if not png_path.exists(): - with output_path.open() as input_file: + with output_path.open(encoding="utf-8") as input_file: cairosvg.svg2png(file_obj=input_file, write_to=str(png_path)) logging.info(f"SVG file is rasterized to {png_path}.") else: