From 6a750aa6e39005c59de62519d3cbc9049dd7d7b6 Mon Sep 17 00:00:00 2001 From: Bryce Kwon Date: Sat, 31 Oct 2026 13:26:41 -0700 Subject: Trim serve.py of a story and an unused parameter Nothing passes parse_args an argv, since t0401 imports only split_cgi_output. --- tools/serve.py | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) (limited to 'tools') diff --git a/tools/serve.py b/tools/serve.py index 8924e53..492345e 100755 --- a/tools/serve.py +++ b/tools/serve.py @@ -65,12 +65,9 @@ def split_cgi_output(output: bytes) -> CgiResponse: The header block ends at the first blank line. cgit ends its lines with a bare LF while a filter writing its own headers may use CRLF, so whichever - terminator appears earliest is the real one. Looking for CRLF everywhere - before falling back to LF would instead find the first CRLF in the body, - and a commit message with DOS line endings has one, which swallowed the - whole document head into the headers. Splitting on the separator rather - than on a non-empty body keeps a legitimately empty body, such as the one - a redirect leaves behind, from being read as headers. + terminator appears earliest is the real one, and a later blank line of the + other kind, such as one in a commit message with DOS line endings, belongs + to the body. The body may also be empty, as a redirect leaves it. """ ends = [(at, len(sep)) for sep in (b"\r\n\r\n", b"\n\n") if (at := output.find(sep)) >= 0] if ends: @@ -233,8 +230,6 @@ class CgitHandler(BaseHTTPRequestHandler): _ = self.wfile.write(response.body) def log_message(self, format: str, *args: object) -> None: - # The signature matches BaseHTTPRequestHandler, so the parameter here - # shadows the builtin of the same name. _ = sys.stderr.write(f" {format % args}\n") @@ -262,14 +257,14 @@ class Options(argparse.Namespace): data: str = str(REPO_ROOT / "assets") -def parse_args(argv: list[str] | None = None) -> Options: +def parse_args() -> Options: parser = argparse.ArgumentParser(description="Preview cgit locally.") _ = parser.add_argument("--config", default=Options.config, help="path to cgitrc (default: ./cgitrc)") _ = parser.add_argument("--port", type=int, default=Options.port) _ = parser.add_argument("--host", default=Options.host) _ = parser.add_argument("--cgit", default=Options.cgit, help="path to the cgit binary") _ = parser.add_argument("--data", default=Options.data, help="directory holding cgit.css, cgit.js, images") - return parser.parse_args(argv, namespace=Options()) + return parser.parse_args(namespace=Options()) def main() -> None: -- cgit