Coverage for slidge/core/mixins/base.py: 100%
25 statements
« prev ^ index » next coverage.py v7.15.2, created at 2026-08-18 04:30 +0000
« prev ^ index » next coverage.py v7.15.2, created at 2026-08-18 04:30 +0000
1from abc import ABC, 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 ...util.types import AnyGateway
13class Base(ABC):
14 """:term:`XMPP Entity` from which slidge sends stanzas."""
16 xmpp: "AnyGateway"
18 jid: JID
19 name: str | None = None
21 @property
22 @abstractmethod
23 def _uploader(self) -> AttachmentUploader:
24 """The :class:`.AttachmentUploader` this entity uploads with."""
25 raise NotImplementedError
27 session: "AnySession | None" = None
28 """Session to which this entity belongs
30 :const:`None` for the gateway component, which is not bound to a :term:`User`.
31 """
34class SessionBound(Base):
35 """:term:`XMPP Entity` that belongs to a :term:`User`'s session.
37 Everything except the gateway component itself, which sends stanzas on its
38 own behalf rather than on behalf of a user.
39 """
41 session: AnySession
43 @property
44 def _uploader(self) -> "AttachmentUploader":
45 return AttachmentUploader(self.xmpp, self.session)
47 @property
48 def user_jid(self) -> JID:
49 return self.session.user_jid
51 @property
52 def user_pk(self) -> int:
53 return self.session.user_pk
56class BaseSender(Base):
57 is_participant: bool = False
59 def _send(
60 self,
61 stanza: MessageOrPresenceTypeVar,
62 **send_kwargs: Any, # noqa:ANN401
63 ) -> MessageOrPresenceTypeVar:
64 raise NotImplementedError