2
0
Эх сурвалжийг харах

Fix import failure when sys.stdin is None

Fixes #1939
Jelmer Vernooij 3 сар өмнө
parent
commit
5cc137671a
2 өөрчлөгдсөн 12 нэмэгдсэн , 2 устгасан
  1. 5 0
      NEWS
  2. 7 2
      dulwich/server.py

+ 5 - 0
NEWS

@@ -1,5 +1,10 @@
 0.24.6	2025-10-17
 
+ * Fix import failure when ``sys.stdin`` is ``None``. The ``dulwich.server``
+   module can now be imported in environments where ``sys.stdin`` is ``None``,
+   such as Windows GUI apps, apps started with ``pythonw``, or apps using
+   ``ProcessPoolExecutor``. (Jelmer Vernooij, #1939)
+
  * Add ``dulwich grep`` command.
    Supports regular expressions, case-insensitive search, line numbers, pathspec
    filtering, and respecting .gitignore patterns. (Jelmer Vernooij, #1776)

+ 7 - 2
dulwich/server.py

@@ -1680,8 +1680,8 @@ def serve_command(
     handler_cls: type[Handler],
     argv: list[str] = sys.argv,
     backend: Optional[Backend] = None,
-    inf: IO[bytes] = sys.stdin.buffer,
-    outf: IO[bytes] = sys.stdout.buffer,
+    inf: Optional[IO[bytes]] = None,
+    outf: Optional[IO[bytes]] = None,
 ) -> int:
     """Serve a single command.
 
@@ -1699,6 +1699,11 @@ def serve_command(
     if backend is None:
         backend = FileSystemBackend()
 
+    if inf is None:
+        inf = sys.stdin.buffer
+    if outf is None:
+        outf = sys.stdout.buffer
+
     def send_fn(data: bytes) -> None:
         outf.write(data)
         outf.flush()