diff --git a/roentgen/server.py b/roentgen/server.py index 00c44f5..b951987 100644 --- a/roentgen/server.py +++ b/roentgen/server.py @@ -2,7 +2,7 @@ Röntgen tile server for sloppy maps. """ import logging -from http.server import BaseHTTPRequestHandler, HTTPServer +from http.server import SimpleHTTPRequestHandler, HTTPServer from pathlib import Path from typing import Optional @@ -15,7 +15,7 @@ __author__ = "Sergey Vartanov" __email__ = "me@enzet.ru" -class Handler(BaseHTTPRequestHandler): +class Handler(SimpleHTTPRequestHandler): """ HTTP request handler that process sloppy map tile requests. """ @@ -43,7 +43,10 @@ class Handler(BaseHTTPRequestHandler): if not svg_path.exists(): tile = Tile(x, y, zoom) tile.draw(tile_path, self.cache) - cairosvg.svg2png(file_obj=svg_path, write_to=str(png_path)) + with svg_path.open() as input_file: + cairosvg.svg2png( + file_obj=input_file, write_to=str(png_path) + ) logging.info(f"SVG file is rasterized to {png_path}.") if zoom != 18: return diff --git a/roentgen/tile.py b/roentgen/tile.py index 5e14cc6..63a8528 100644 --- a/roentgen/tile.py +++ b/roentgen/tile.py @@ -84,7 +84,10 @@ class Tiles: output_path: Path = file_path.with_suffix(".png") if not output_path.exists(): - cairosvg.svg2png(file_obj=file_path, write_to=str(output_path)) + with file_path.open() as input_file: + cairosvg.svg2png( + file_obj=input_file, write_to=str(output_path) + ) logging.info(f"SVG file is rasterized to {output_path}.") else: logging.info(f"File {output_path} already exists.") @@ -136,7 +139,8 @@ class Tiles: png_path: Path = cache_path / f"{self.boundary_box.get_format()}.png" if not png_path.exists(): - cairosvg.svg2png(file_obj=output_path, write_to=str(png_path)) + with output_path.open() 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: logging.info(f"File {png_path} already exists.")