From 9c20c6818e8e8b44fb1616c5f79536fd96531b22 Mon Sep 17 00:00:00 2001 From: Zhang Yanpo Date: Sun, 22 Feb 2026 20:16:55 +0800 Subject: [PATCH] refactor: rename input param to content in convert() and render_to_img() Avoids shadowing Python builtin input(). All existing callers use positional arguments so this is backwards-compatible. Co-Authored-By: Claude Opus 4.6 --- down2.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/down2.py b/down2.py index bd3516c..a8822d6 100755 --- a/down2.py +++ b/down2.py @@ -61,7 +61,7 @@ def _shutdown_browser() -> None: ) -def convert(input_typ: str, input: str | bytes, output_typ: str, opt: dict[str, dict] | None = None) -> str | bytes: +def convert(input_typ: str, content: str | bytes, output_typ: str, opt: dict[str, dict] | None = None) -> str | bytes: conv = mappings.get((input_typ, output_typ)) if conv is None: raise ValueError(f"unsupported conversion: {input_typ} -> {output_typ}") @@ -69,10 +69,10 @@ def convert(input_typ: str, input: str | bytes, output_typ: str, opt: dict[str, kwargs = {} if opt is not None and input_typ in opt: kwargs = opt[input_typ] - return conv(input, **kwargs) + return conv(content, **kwargs) else: # indirect convertion - inp = convert(input_typ, input, conv, opt=opt) + inp = convert(input_typ, content, conv, opt=opt) return convert(conv, inp, output_typ, opt=opt) @@ -322,7 +322,7 @@ def web_to_img(pagefn: str, typ: str) -> bytes: def render_to_img( - mime: str, input: str | bytes, typ: str, width: int = 1000, height: int = 2000, asset_base: str | None = None + mime: str, content: str | bytes, typ: str, width: int = 1000, height: int = 2000, asset_base: str | None = None ) -> bytes: """ Render content that is renderable in a browser to image. @@ -332,7 +332,7 @@ def render_to_img( Args: mime(str): a full mime type such as ``image/jpeg`` or a shortcut ``jpg``. - input(str): content of the input, such as jpeg data or svg source file. + content(str): content to render, such as jpeg data or svg source. typ(string): specifies output image type such as "png", "jpg" @@ -347,11 +347,11 @@ def render_to_img( """ if "html" in mime: - input = r'' + input + content = r'' + content if asset_base is not None: base_uri = pathlib.Path(asset_base).as_uri() - input = ''.format(base_uri) + input + content = ''.format(base_uri) + content m = mimetypes.get(mime) or mime suffix = mime_to_suffix.get(m, mime) @@ -359,10 +359,10 @@ def render_to_img( with tempfile.TemporaryDirectory() as tdir: fn = os.path.join(tdir, "xxx." + suffix) flags = "w" - if isinstance(input, bytes): + if isinstance(content, bytes): flags = "wb" with open(fn, flags) as f: - f.write(input) + f.write(content) browser = _get_browser() page = browser.new_page(