Voice et bot modif

This commit is contained in:
pi 2026-06-16 17:09:34 +00:00
parent 189d56026b
commit 7333a22bcd
10774 changed files with 634644 additions and 933308 deletions

View file

@ -6,6 +6,7 @@ import re
import sys
import typing as t
from functools import update_wrapper
from gettext import gettext as _
from types import ModuleType
from types import TracebackType
@ -57,7 +58,10 @@ def make_str(value: t.Any) -> str:
def make_default_short_help(help: str, max_length: int = 45) -> str:
"""Returns a condensed version of help string."""
"""Returns a condensed version of help string.
:meta private:
"""
# Consider only the first paragraph.
paragraph_end = help.find("\n\n")
@ -113,6 +117,14 @@ class LazyFile:
files for writing.
"""
name: str
mode: str
encoding: str | None
errors: str | None
atomic: bool
_f: t.IO[t.Any] | None
should_close: bool
def __init__(
self,
filename: str | os.PathLike[str],
@ -120,14 +132,12 @@ class LazyFile:
encoding: str | None = None,
errors: str | None = "strict",
atomic: bool = False,
):
self.name: str = os.fspath(filename)
) -> None:
self.name = os.fspath(filename)
self.mode = mode
self.encoding = encoding
self.errors = errors
self.atomic = atomic
self._f: t.IO[t.Any] | None
self.should_close: bool
if self.name == "-":
self._f, self.should_close = open_stream(filename, mode, encoding, errors)
@ -195,8 +205,10 @@ class LazyFile:
class KeepOpenFile:
_file: t.IO[t.Any]
def __init__(self, file: t.IO[t.Any]) -> None:
self._file: t.IO[t.Any] = file
self._file = file
def __getattr__(self, name: str) -> t.Any:
return getattr(self._file, name)
@ -220,7 +232,7 @@ class KeepOpenFile:
def echo(
message: t.Any | None = None,
message: object = None,
file: t.IO[t.Any] | None = None,
nl: bool = True,
err: bool = False,
@ -275,14 +287,15 @@ def echo(
if file is None:
return
# Convert non bytes/text into the native string type.
if message is not None and not isinstance(message, (str, bytes, bytearray)):
out: str | bytes | bytearray | None = str(message)
else:
out = message
match message:
case str() | bytes() | bytearray():
out = message
case None:
out = ""
case _:
out = str(message)
if nl:
out = out or ""
if isinstance(out, str):
out += "\n"
else:
@ -298,7 +311,6 @@ def echo(
# would expect. Eg: you can write to StringIO for other cases.
if isinstance(out, (bytes, bytearray)):
binary_file = _find_binary_writer(file)
if binary_file is not None:
file.flush()
binary_file.write(out)
@ -330,7 +342,7 @@ def get_binary_stream(name: t.Literal["stdin", "stdout", "stderr"]) -> t.BinaryI
"""
opener = binary_streams.get(name)
if opener is None:
raise TypeError(f"Unknown standard stream '{name}'")
raise TypeError(_("Unknown standard stream '{name}'").format(name=name))
return opener()
@ -351,7 +363,7 @@ def get_text_stream(
"""
opener = text_streams.get(name)
if opener is None:
raise TypeError(f"Unknown standard stream '{name}'")
raise TypeError(_("Unknown standard stream '{name}'").format(name=name))
return opener(encoding, errors)
@ -504,6 +516,8 @@ class PacifyFlushWrapper:
pipe, all calls and attributes are proxied.
"""
wrapped: t.IO[t.Any]
def __init__(self, wrapped: t.IO[t.Any]) -> None:
self.wrapped = wrapped