from typing import Any, LiteralString, NewType import os, shlex ShellQuotedString = NewType("ShellQuotedString", str) ShellString = LiteralString | ShellQuotedString def system(command: ShellString) -> int: return os.system(command) def quote(value: str) -> ShellQuotedString: return ShellQuotedString(shlex.quote(value)) def shell_format( format_string: LiteralString, *args: ShellString, **kwargs: ShellString, ) -> ShellQuotedString: return ShellQuotedString(format_string.format(*args, **kwargs)) def resize(size: str) -> None: command = shell_format("convert INPUT -resize {} OUTPUT", quote(size)) system(command) def api(request: Any) -> None: resize(request.args["size"])