mirror of
https://gitlab.com/MoonTestUse1/AdministrationItDepartmens.git
synced 2025-08-14 00:25:46 +02:00
Проверка 09.02.2025
This commit is contained in:
@@ -2,7 +2,6 @@ from __future__ import annotations
|
||||
|
||||
import asyncio
|
||||
import functools
|
||||
import re
|
||||
import sys
|
||||
import typing
|
||||
from contextlib import contextmanager
|
||||
@@ -17,7 +16,7 @@ else: # pragma: no cover
|
||||
has_exceptiongroups = True
|
||||
if sys.version_info < (3, 11): # pragma: no cover
|
||||
try:
|
||||
from exceptiongroup import BaseExceptionGroup
|
||||
from exceptiongroup import BaseExceptionGroup # type: ignore[unused-ignore,import-not-found]
|
||||
except ImportError:
|
||||
has_exceptiongroups = False
|
||||
|
||||
@@ -26,41 +25,31 @@ AwaitableCallable = typing.Callable[..., typing.Awaitable[T]]
|
||||
|
||||
|
||||
@typing.overload
|
||||
def is_async_callable(obj: AwaitableCallable[T]) -> TypeGuard[AwaitableCallable[T]]:
|
||||
...
|
||||
def is_async_callable(obj: AwaitableCallable[T]) -> TypeGuard[AwaitableCallable[T]]: ...
|
||||
|
||||
|
||||
@typing.overload
|
||||
def is_async_callable(obj: typing.Any) -> TypeGuard[AwaitableCallable[typing.Any]]:
|
||||
...
|
||||
def is_async_callable(obj: typing.Any) -> TypeGuard[AwaitableCallable[typing.Any]]: ...
|
||||
|
||||
|
||||
def is_async_callable(obj: typing.Any) -> typing.Any:
|
||||
while isinstance(obj, functools.partial):
|
||||
obj = obj.func
|
||||
|
||||
return asyncio.iscoroutinefunction(obj) or (
|
||||
callable(obj) and asyncio.iscoroutinefunction(obj.__call__)
|
||||
)
|
||||
return asyncio.iscoroutinefunction(obj) or (callable(obj) and asyncio.iscoroutinefunction(obj.__call__))
|
||||
|
||||
|
||||
T_co = typing.TypeVar("T_co", covariant=True)
|
||||
|
||||
|
||||
class AwaitableOrContextManager(
|
||||
typing.Awaitable[T_co], typing.AsyncContextManager[T_co], typing.Protocol[T_co]
|
||||
):
|
||||
...
|
||||
class AwaitableOrContextManager(typing.Awaitable[T_co], typing.AsyncContextManager[T_co], typing.Protocol[T_co]): ...
|
||||
|
||||
|
||||
class SupportsAsyncClose(typing.Protocol):
|
||||
async def close(self) -> None:
|
||||
... # pragma: no cover
|
||||
async def close(self) -> None: ... # pragma: no cover
|
||||
|
||||
|
||||
SupportsAsyncCloseType = typing.TypeVar(
|
||||
"SupportsAsyncCloseType", bound=SupportsAsyncClose, covariant=False
|
||||
)
|
||||
SupportsAsyncCloseType = typing.TypeVar("SupportsAsyncCloseType", bound=SupportsAsyncClose, covariant=False)
|
||||
|
||||
|
||||
class AwaitableOrContextManagerWrapper(typing.Generic[SupportsAsyncCloseType]):
|
||||
@@ -86,14 +75,26 @@ def collapse_excgroups() -> typing.Generator[None, None, None]:
|
||||
try:
|
||||
yield
|
||||
except BaseException as exc:
|
||||
if has_exceptiongroups:
|
||||
if has_exceptiongroups: # pragma: no cover
|
||||
while isinstance(exc, BaseExceptionGroup) and len(exc.exceptions) == 1:
|
||||
exc = exc.exceptions[0] # pragma: no cover
|
||||
exc = exc.exceptions[0]
|
||||
|
||||
raise exc
|
||||
|
||||
|
||||
def get_route_path(scope: Scope) -> str:
|
||||
path: str = scope["path"]
|
||||
root_path = scope.get("root_path", "")
|
||||
route_path = re.sub(r"^" + root_path, "", scope["path"])
|
||||
return route_path
|
||||
if not root_path:
|
||||
return path
|
||||
|
||||
if not path.startswith(root_path):
|
||||
return path
|
||||
|
||||
if path == root_path:
|
||||
return ""
|
||||
|
||||
if path[len(root_path)] == "/":
|
||||
return path[len(root_path) :]
|
||||
|
||||
return path
|
||||
|
Reference in New Issue
Block a user