From 2d7770a755b5786cc98ae79d468e288a5f8e9b7a Mon Sep 17 00:00:00 2001 From: Daniel Rojas Date: Sun, 6 Dec 2020 13:03:26 +0100 Subject: [PATCH] Apply more suggestions by @kvid --- src/wireviz/svgembed.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/wireviz/svgembed.py b/src/wireviz/svgembed.py index 69961dd4..ea802ca9 100644 --- a/src/wireviz/svgembed.py +++ b/src/wireviz/svgembed.py @@ -4,6 +4,7 @@ import re import base64 from pathlib import Path +from typing import Union mime_subtype_replacements = {'jpg': 'jpeg', 'tif': 'tiff'} @@ -25,15 +26,15 @@ def embed_svg_images(svg_in: str, base_path: Path): return svg_out -def get_mime_subtype(filename: Path): - mime_subtype = filename.suffix.lstrip('.').lower() +def get_mime_subtype(filename: Union[str, Path]): + mime_subtype = Path(filename).suffix.lstrip('.').lower() if mime_subtype in mime_subtype_replacements: mime_subtype = mime_subtype_replacements[mime_subtype] return mime_subtype -def embed_svg_images_file(filename_in: Path, overwrite: bool = True): - filename_in = filename_in.resolve() +def embed_svg_images_file(filename_in: Union[str, Path], overwrite: bool = True): + filename_in = Path(filename_in).resolve() filename_out = filename_in.with_suffix('.b64.svg') filename_out.write_text(embed_svg_images(filename_in.read_text(), filename_in.parent)) if overwrite: