Coverage for slidge/core/mixins/base.py: 96%
28 statements
« prev ^ index » next coverage.py v7.17.0, created at 2026-11-10 12:26 +0000
« prev ^ index » next coverage.py v7.17.0, created at 2026-11-10 12:26 +0000
1from abc import abstractmethod
2from typing import TYPE_CHECKING, Any
4from slixmpp import JID
6from ...util.types import AnySession, MessageOrPresenceTypeVar
7from ..attachment_upload import AttachmentUploader
9if TYPE_CHECKING:
10 # from ...core.session import BaseSession
11 from ...util.types import AnyGateway
14class Base:
15 """:term:`XMPP Entity` from which slidge sends stanzas."""
17 xmpp: "AnyGateway"
19 @property
20 @abstractmethod
21 def jid(self) -> JID: ...
23 name: str | None = None
25 @property
26 @abstractmethod
27 def _uploader(self) -> AttachmentUploader:
28 """The :class:`.AttachmentUploader` this entity uploads with."""
29 raise NotImplementedError
31 _session: "AnySession | None" = None
32 """Session to which this entity belongs
34 :const:`None` for the gateway component, which is not bound to a :term:`User`.
35 """
38class SessionBound(Base):
39 """:term:`XMPP Entity` that belongs to a :term:`User`'s session.
41 Everything except the gateway component itself, which sends stanzas on its
42 own behalf rather than on behalf of a user.
43 """
45 _session: AnySession
47 @property
48 def _uploader(self) -> "AttachmentUploader":
49 return AttachmentUploader(self.xmpp, self._session)
51 @property
52 def user_jid(self) -> JID:
53 return self._session.user_jid
55 @property
56 def user_pk(self) -> int:
57 return self._session.user_pk
60class BaseSender(Base):
61 is_participant: bool = False
63 def _send(
64 self,
65 stanza: MessageOrPresenceTypeVar,
66 **send_kwargs: Any, # noqa:ANN401
67 ) -> MessageOrPresenceTypeVar:
68 raise NotImplementedError