Voice et bot modif
This commit is contained in:
parent
189d56026b
commit
7333a22bcd
10774 changed files with 634644 additions and 933308 deletions
|
|
@ -3,12 +3,14 @@ import signal
|
|||
import socket
|
||||
import warnings
|
||||
from abc import ABC, abstractmethod
|
||||
from typing import TYPE_CHECKING, Any, List, Optional, Set
|
||||
from typing import TYPE_CHECKING, Any
|
||||
|
||||
from yarl import URL
|
||||
|
||||
from .abc import AbstractAccessLogger
|
||||
from .typedefs import PathLike
|
||||
from .web_app import Application
|
||||
from .web_log import AccessLogger
|
||||
from .web_server import Server
|
||||
|
||||
if TYPE_CHECKING:
|
||||
|
|
@ -48,7 +50,7 @@ class BaseSite(ABC):
|
|||
runner: "BaseRunner",
|
||||
*,
|
||||
shutdown_timeout: float = 60.0,
|
||||
ssl_context: Optional[SSLContext] = None,
|
||||
ssl_context: SSLContext | None = None,
|
||||
backlog: int = 128,
|
||||
) -> None:
|
||||
if runner.server is None:
|
||||
|
|
@ -60,7 +62,7 @@ class BaseSite(ABC):
|
|||
self._runner = runner
|
||||
self._ssl_context = ssl_context
|
||||
self._backlog = backlog
|
||||
self._server: Optional[asyncio.AbstractServer] = None
|
||||
self._server: asyncio.AbstractServer | None = None
|
||||
|
||||
@property
|
||||
@abstractmethod
|
||||
|
|
@ -80,19 +82,19 @@ class BaseSite(ABC):
|
|||
|
||||
|
||||
class TCPSite(BaseSite):
|
||||
__slots__ = ("_host", "_port", "_reuse_address", "_reuse_port")
|
||||
__slots__ = ("_host", "_port", "_bound_port", "_reuse_address", "_reuse_port")
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
runner: "BaseRunner",
|
||||
host: Optional[str] = None,
|
||||
port: Optional[int] = None,
|
||||
host: str | None = None,
|
||||
port: int | None = None,
|
||||
*,
|
||||
shutdown_timeout: float = 60.0,
|
||||
ssl_context: Optional[SSLContext] = None,
|
||||
ssl_context: SSLContext | None = None,
|
||||
backlog: int = 128,
|
||||
reuse_address: Optional[bool] = None,
|
||||
reuse_port: Optional[bool] = None,
|
||||
reuse_address: bool | None = None,
|
||||
reuse_port: bool | None = None,
|
||||
) -> None:
|
||||
super().__init__(
|
||||
runner,
|
||||
|
|
@ -104,14 +106,29 @@ class TCPSite(BaseSite):
|
|||
if port is None:
|
||||
port = 8443 if self._ssl_context else 8080
|
||||
self._port = port
|
||||
self._bound_port: int | None = None
|
||||
self._reuse_address = reuse_address
|
||||
self._reuse_port = reuse_port
|
||||
|
||||
@property
|
||||
def port(self) -> int:
|
||||
"""The port the server is listening on.
|
||||
|
||||
If the server hasn't been started yet, this returns the requested port
|
||||
(which might be 0 for a dynamic port).
|
||||
After the server starts, it returns the actual bound port. This is
|
||||
especially useful when port=0 was requested, as it allows retrieving the
|
||||
dynamically assigned port after the site has started.
|
||||
"""
|
||||
if self._bound_port is not None:
|
||||
return self._bound_port
|
||||
return self._port
|
||||
|
||||
@property
|
||||
def name(self) -> str:
|
||||
scheme = "https" if self._ssl_context else "http"
|
||||
host = "0.0.0.0" if not self._host else self._host
|
||||
return str(URL.build(scheme=scheme, host=host, port=self._port))
|
||||
return str(URL.build(scheme=scheme, host=host, port=self.port))
|
||||
|
||||
async def start(self) -> None:
|
||||
await super().start()
|
||||
|
|
@ -127,6 +144,10 @@ class TCPSite(BaseSite):
|
|||
reuse_address=self._reuse_address,
|
||||
reuse_port=self._reuse_port,
|
||||
)
|
||||
if self._server.sockets:
|
||||
self._bound_port = self._server.sockets[0].getsockname()[1]
|
||||
else:
|
||||
self._bound_port = self._port
|
||||
|
||||
|
||||
class UnixSite(BaseSite):
|
||||
|
|
@ -138,7 +159,7 @@ class UnixSite(BaseSite):
|
|||
path: PathLike,
|
||||
*,
|
||||
shutdown_timeout: float = 60.0,
|
||||
ssl_context: Optional[SSLContext] = None,
|
||||
ssl_context: SSLContext | None = None,
|
||||
backlog: int = 128,
|
||||
) -> None:
|
||||
super().__init__(
|
||||
|
|
@ -207,7 +228,7 @@ class SockSite(BaseSite):
|
|||
sock: socket.socket,
|
||||
*,
|
||||
shutdown_timeout: float = 60.0,
|
||||
ssl_context: Optional[SSLContext] = None,
|
||||
ssl_context: SSLContext | None = None,
|
||||
backlog: int = 128,
|
||||
) -> None:
|
||||
super().__init__(
|
||||
|
|
@ -251,17 +272,17 @@ class BaseRunner(ABC):
|
|||
) -> None:
|
||||
self._handle_signals = handle_signals
|
||||
self._kwargs = kwargs
|
||||
self._server: Optional[Server] = None
|
||||
self._sites: List[BaseSite] = []
|
||||
self._server: Server | None = None
|
||||
self._sites: list[BaseSite] = []
|
||||
self._shutdown_timeout = shutdown_timeout
|
||||
|
||||
@property
|
||||
def server(self) -> Optional[Server]:
|
||||
def server(self) -> Server | None:
|
||||
return self._server
|
||||
|
||||
@property
|
||||
def addresses(self) -> List[Any]:
|
||||
ret: List[Any] = []
|
||||
def addresses(self) -> list[Any]:
|
||||
ret: list[Any] = []
|
||||
for site in self._sites:
|
||||
server = site._server
|
||||
if server is not None:
|
||||
|
|
@ -272,7 +293,7 @@ class BaseRunner(ABC):
|
|||
return ret
|
||||
|
||||
@property
|
||||
def sites(self) -> Set[BaseSite]:
|
||||
def sites(self) -> set[BaseSite]:
|
||||
return set(self._sites)
|
||||
|
||||
async def setup(self) -> None:
|
||||
|
|
@ -369,14 +390,19 @@ class AppRunner(BaseRunner):
|
|||
__slots__ = ("_app",)
|
||||
|
||||
def __init__(
|
||||
self, app: Application, *, handle_signals: bool = False, **kwargs: Any
|
||||
self,
|
||||
app: Application,
|
||||
*,
|
||||
handle_signals: bool = False,
|
||||
access_log_class: type[AbstractAccessLogger] = AccessLogger,
|
||||
**kwargs: Any,
|
||||
) -> None:
|
||||
super().__init__(handle_signals=handle_signals, **kwargs)
|
||||
if not isinstance(app, Application):
|
||||
raise TypeError(
|
||||
"The first argument should be web.Application "
|
||||
"instance, got {!r}".format(app)
|
||||
f"The first argument should be web.Application instance, got {app!r}"
|
||||
)
|
||||
self._kwargs["access_log_class"] = access_log_class
|
||||
self._app = app
|
||||
|
||||
@property
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue