From 0ffad9d2141881ca7eb022256c35d45bf30260af Mon Sep 17 00:00:00 2001 From: AURUMVORXX Date: Sun, 26 Oct 2025 01:03:27 +0500 Subject: [PATCH] =?UTF-8?q?feat:=20=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=B0=20=D0=B1=D0=B8=D0=B1=D0=BB=D0=B8=D0=BE=D1=82?= =?UTF-8?q?=D0=B5=D0=BA=D0=B0=20Loguru?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pyproject.toml | 3 ++- src/pyg2o/server.py | 13 ++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index befcd85..93e2bda 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -5,7 +5,8 @@ description = "" readme = "README.md" requires-python = ">=3.14" dependencies = [ - "fastapi>=0.116.1", + "fastapi>=0.120.0", + "loguru>=0.7.3", "uvicorn>=0.35.0", "websockets>=15.0.1", ] diff --git a/src/pyg2o/server.py b/src/pyg2o/server.py index 06d581f..300ea9f 100644 --- a/src/pyg2o/server.py +++ b/src/pyg2o/server.py @@ -1,6 +1,6 @@ from __future__ import annotations import json -import logging +import loguru import asyncio from weakref import WeakValueDictionary, WeakSet, finalize from collections import UserDict @@ -18,7 +18,7 @@ class TopicWeakDict(UserDict): super().__setitem__(key, value) class Server: - _logger: logging.Logger = logging.getLogger(__name__) + _logger: loguru.Logger = loguru.logger _static_tokens: list[str] = [] _temp_tokens: list[str] = [] _requests: WeakValueDictionary[str, asyncio.Future] = WeakValueDictionary() @@ -27,7 +27,6 @@ class Server: @classmethod def init(cls, *, app: FastAPI, static_tokens: list[str] = []): - cls._logger.addHandler(logging.NullHandler()) cls._static_tokens = static_tokens cls._requests: WeakValueDictionary[str, asyncio.Future] = WeakValueDictionary() @@ -76,7 +75,7 @@ class Server: @classmethod def _register_routes(cls, app): @app.websocket('/pyg2o') - async def pyg2o(websocket: WebSocket, token: str, topics: str): + async def pyg2o(websocket: WebSocket, token: str, topics: str | None): await cls._handle_connection(websocket, token, topics) _ = pyg2o @@ -96,10 +95,10 @@ class Server: cls._topics[topic].discard(connection) @classmethod - async def _handle_connection(cls, connection: WebSocket, token: str, topics: str): + async def _handle_connection(cls, connection: WebSocket, token: str, topics: str | None): + cls._logger.exception(f'PyG2O соединение отклонено: получен токен {token}\nStatic Tokens: {cls._static_tokens}') if not await cls._process_query_params(connection, token, topics): - cls._logger.exception(f'PyG2O соединение отклонено: получен токен {token}\nStatic Tokens: {cls._static_tokens}') await connection.close() return @@ -120,7 +119,7 @@ class Server: cls._logger.exception(f'Ошибка WebSocket подключения: {e}') @classmethod - async def _process_query_params(cls, connection: WebSocket, token: str, topics: str) -> bool: + async def _process_query_params(cls, connection: WebSocket, token: str, topics: str | None) -> bool: if token not in cls._static_tokens and token not in cls._temp_tokens: return False