clan-app: change ApiBridge ABC class to Protocol

This commit is contained in:
Qubasa
2025-09-16 11:48:59 +02:00
parent 1b193123b2
commit ee0f111fc9
2 changed files with 10 additions and 11 deletions

View File

@@ -1,9 +1,8 @@
import logging
import threading
from abc import ABC, abstractmethod
from contextlib import ExitStack
from dataclasses import dataclass, field
from typing import TYPE_CHECKING, Any
from dataclasses import dataclass
from typing import TYPE_CHECKING, Any, Protocol
from clan_lib.api import ApiError, ApiResponse, ErrorDataClass
from clan_lib.api.tasks import WebThread
@@ -30,16 +29,13 @@ class BackendResponse:
_op_key: str
@dataclass
class ApiBridge(ABC):
class ApiBridge(Protocol):
"""Generic interface for API bridges that can handle method calls from different sources."""
middleware_chain: tuple["Middleware", ...]
threads: dict[str, WebThread] = field(default_factory=dict)
threads: dict[str, WebThread]
@abstractmethod
def send_api_response(self, response: BackendResponse) -> None:
"""Send response back to the client."""
def send_api_response(self, response: BackendResponse) -> None: ...
def process_request(self, request: BackendRequest) -> None:
"""Process an API request through the middleware chain."""

View File

@@ -1,6 +1,6 @@
import json
import logging
from dataclasses import dataclass
from dataclasses import dataclass, field
from typing import TYPE_CHECKING
from clan_lib.api import dataclass_to_dict
@@ -9,6 +9,8 @@ from clan_lib.api.tasks import WebThread
from clan_app.api.api_bridge import ApiBridge, BackendRequest, BackendResponse
if TYPE_CHECKING:
from clan_app.api.middleware import Middleware
from .webview import Webview
log = logging.getLogger(__name__)
@@ -19,7 +21,8 @@ class WebviewBridge(ApiBridge):
"""Webview-specific implementation of the API bridge."""
webview: "Webview"
threads: dict[str, WebThread] # Inherited from ApiBridge
middleware_chain: tuple["Middleware", ...]
threads: dict[str, WebThread] = field(default_factory=dict)
def send_api_response(self, response: BackendResponse) -> None:
"""Send response back to the webview client."""