2024-07-12 02:30:17 +02:00
|
|
|
from typing import TYPE_CHECKING, Optional
|
2016-11-27 06:14:48 +01:00
|
|
|
|
2022-09-22 22:09:34 +02:00
|
|
|
from django.conf import settings
|
|
|
|
|
2019-07-30 20:58:48 +02:00
|
|
|
if TYPE_CHECKING:
|
2018-03-15 01:21:27 +01:00
|
|
|
from zerver.tornado.event_queue import ClientDescriptor
|
2016-11-27 06:14:48 +01:00
|
|
|
|
2024-07-12 02:30:17 +02:00
|
|
|
descriptors_by_handler_id: dict[int, "ClientDescriptor"] = {}
|
2016-11-27 06:14:48 +01:00
|
|
|
|
2021-02-12 08:19:30 +01:00
|
|
|
|
2021-02-12 08:20:45 +01:00
|
|
|
def get_descriptor_by_handler_id(handler_id: int) -> Optional["ClientDescriptor"]:
|
2016-11-27 06:14:48 +01:00
|
|
|
return descriptors_by_handler_id.get(handler_id)
|
|
|
|
|
2021-02-12 08:19:30 +01:00
|
|
|
|
2021-02-12 08:20:45 +01:00
|
|
|
def set_descriptor_by_handler_id(handler_id: int, client_descriptor: "ClientDescriptor") -> None:
|
2016-11-27 06:14:48 +01:00
|
|
|
descriptors_by_handler_id[handler_id] = client_descriptor
|
|
|
|
|
2021-02-12 08:19:30 +01:00
|
|
|
|
2020-07-05 02:29:31 +02:00
|
|
|
def clear_descriptor_by_handler_id(handler_id: int) -> None:
|
2016-11-27 06:14:48 +01:00
|
|
|
del descriptors_by_handler_id[handler_id]
|
2022-09-22 22:09:34 +02:00
|
|
|
|
|
|
|
|
2024-07-12 02:30:23 +02:00
|
|
|
current_port: int | None = None
|
2022-09-22 22:09:34 +02:00
|
|
|
|
|
|
|
|
2024-07-12 02:30:23 +02:00
|
|
|
def is_current_port(port: int) -> int | None:
|
2022-09-22 22:09:34 +02:00
|
|
|
return settings.TEST_SUITE or current_port == port
|
|
|
|
|
|
|
|
|
|
|
|
def set_current_port(port: int) -> None:
|
|
|
|
global current_port
|
|
|
|
current_port = port
|