Created
May 20, 2022 18:14
Shared via mypy Playground
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment