Skip to content

Instantly share code, notes, and snippets.

@mypy-play
Created May 20, 2022 18:14
Shared via mypy Playground
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