Voice et bot modif
This commit is contained in:
parent
189d56026b
commit
7333a22bcd
10774 changed files with 634644 additions and 933308 deletions
|
|
@ -6,7 +6,7 @@ import contextlib
|
|||
import functools
|
||||
import itertools
|
||||
import socket
|
||||
from typing import List, Optional, Sequence, Set, Union
|
||||
from collections.abc import Sequence
|
||||
|
||||
from . import _staggered
|
||||
from .types import AddrInfoType, SocketFactoryType
|
||||
|
|
@ -15,11 +15,11 @@ from .types import AddrInfoType, SocketFactoryType
|
|||
async def start_connection(
|
||||
addr_infos: Sequence[AddrInfoType],
|
||||
*,
|
||||
local_addr_infos: Optional[Sequence[AddrInfoType]] = None,
|
||||
happy_eyeballs_delay: Optional[float] = None,
|
||||
interleave: Optional[int] = None,
|
||||
loop: Optional[asyncio.AbstractEventLoop] = None,
|
||||
socket_factory: Optional[SocketFactoryType] = None,
|
||||
local_addr_infos: Sequence[AddrInfoType] | None = None,
|
||||
happy_eyeballs_delay: float | None = None,
|
||||
interleave: int | None = None,
|
||||
loop: asyncio.AbstractEventLoop | None = None,
|
||||
socket_factory: SocketFactoryType | None = None,
|
||||
) -> socket.socket:
|
||||
"""
|
||||
Connect to a TCP server.
|
||||
|
|
@ -51,8 +51,10 @@ async def start_connection(
|
|||
transport, protocol = await loop.create_connection(
|
||||
MyProtocol, sock=socket, ...)
|
||||
"""
|
||||
if not (current_loop := loop):
|
||||
current_loop = asyncio.get_running_loop()
|
||||
if not addr_infos:
|
||||
raise ValueError("addr_infos must not be empty")
|
||||
|
||||
current_loop = loop or asyncio.get_running_loop()
|
||||
|
||||
single_addr_info = len(addr_infos) == 1
|
||||
|
||||
|
|
@ -63,9 +65,9 @@ async def start_connection(
|
|||
if interleave and not single_addr_info:
|
||||
addr_infos = _interleave_addrinfos(addr_infos, interleave)
|
||||
|
||||
sock: Optional[socket.socket] = None
|
||||
sock: socket.socket | None = None
|
||||
# uvloop can raise RuntimeError instead of OSError
|
||||
exceptions: List[List[Union[OSError, RuntimeError]]] = []
|
||||
exceptions: list[list[OSError | RuntimeError]] = []
|
||||
if happy_eyeballs_delay is None or single_addr_info:
|
||||
# not using happy eyeballs
|
||||
for addrinfo in addr_infos:
|
||||
|
|
@ -82,7 +84,7 @@ async def start_connection(
|
|||
except (RuntimeError, OSError):
|
||||
continue
|
||||
else: # using happy eyeballs
|
||||
open_sockets: Set[socket.socket] = set()
|
||||
open_sockets: set[socket.socket] = set()
|
||||
try:
|
||||
sock, _, _ = await _staggered.staggered_race(
|
||||
(
|
||||
|
|
@ -156,11 +158,11 @@ async def start_connection(
|
|||
|
||||
async def _connect_sock(
|
||||
loop: asyncio.AbstractEventLoop,
|
||||
exceptions: List[List[Union[OSError, RuntimeError]]],
|
||||
exceptions: list[list[OSError | RuntimeError]],
|
||||
addr_info: AddrInfoType,
|
||||
local_addr_infos: Optional[Sequence[AddrInfoType]] = None,
|
||||
open_sockets: Optional[Set[socket.socket]] = None,
|
||||
socket_factory: Optional[SocketFactoryType] = None,
|
||||
local_addr_infos: Sequence[AddrInfoType] | None = None,
|
||||
open_sockets: set[socket.socket] | None = None,
|
||||
socket_factory: SocketFactoryType | None = None,
|
||||
) -> socket.socket:
|
||||
"""
|
||||
Create, bind and connect one socket.
|
||||
|
|
@ -172,7 +174,7 @@ async def _connect_sock(
|
|||
of all staggered tasks in the result there are runner up sockets aka
|
||||
multiple winners.
|
||||
"""
|
||||
my_exceptions: List[Union[OSError, RuntimeError]] = []
|
||||
my_exceptions: list[OSError | RuntimeError] = []
|
||||
exceptions.append(my_exceptions)
|
||||
family, type_, proto, _, address = addr_info
|
||||
sock = None
|
||||
|
|
@ -234,10 +236,10 @@ async def _connect_sock(
|
|||
|
||||
def _interleave_addrinfos(
|
||||
addrinfos: Sequence[AddrInfoType], first_address_family_count: int = 1
|
||||
) -> List[AddrInfoType]:
|
||||
) -> list[AddrInfoType]:
|
||||
"""Interleave list of addrinfo tuples by family."""
|
||||
# Group addresses by family
|
||||
addrinfos_by_family: collections.OrderedDict[int, List[AddrInfoType]] = (
|
||||
addrinfos_by_family: collections.OrderedDict[int, list[AddrInfoType]] = (
|
||||
collections.OrderedDict()
|
||||
)
|
||||
for addr in addrinfos:
|
||||
|
|
@ -247,7 +249,7 @@ def _interleave_addrinfos(
|
|||
addrinfos_by_family[family].append(addr)
|
||||
addrinfos_lists = list(addrinfos_by_family.values())
|
||||
|
||||
reordered: List[AddrInfoType] = []
|
||||
reordered: list[AddrInfoType] = []
|
||||
if first_address_family_count > 1:
|
||||
reordered.extend(addrinfos_lists[0][: first_address_family_count - 1])
|
||||
del addrinfos_lists[0][: first_address_family_count - 1]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue