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

1from abc import abstractmethod 

2from typing import TYPE_CHECKING, Any 

3 

4from slixmpp import JID 

5 

6from ...util.types import AnySession, MessageOrPresenceTypeVar 

7from ..attachment_upload import AttachmentUploader 

8 

9if TYPE_CHECKING: 

10 # from ...core.session import BaseSession 

11 from ...util.types import AnyGateway 

12 

13 

14class Base: 

15 """:term:`XMPP Entity` from which slidge sends stanzas.""" 

16 

17 xmpp: "AnyGateway" 

18 

19 @property 

20 @abstractmethod 

21 def jid(self) -> JID: ... 

22 

23 name: str | None = None 

24 

25 @property 

26 @abstractmethod 

27 def _uploader(self) -> AttachmentUploader: 

28 """The :class:`.AttachmentUploader` this entity uploads with.""" 

29 raise NotImplementedError 

30 

31 _session: "AnySession | None" = None 

32 """Session to which this entity belongs 

33 

34 :const:`None` for the gateway component, which is not bound to a :term:`User`. 

35 """ 

36 

37 

38class SessionBound(Base): 

39 """:term:`XMPP Entity` that belongs to a :term:`User`'s session. 

40 

41 Everything except the gateway component itself, which sends stanzas on its 

42 own behalf rather than on behalf of a user. 

43 """ 

44 

45 _session: AnySession 

46 

47 @property 

48 def _uploader(self) -> "AttachmentUploader": 

49 return AttachmentUploader(self.xmpp, self._session) 

50 

51 @property 

52 def user_jid(self) -> JID: 

53 return self._session.user_jid 

54 

55 @property 

56 def user_pk(self) -> int: 

57 return self._session.user_pk 

58 

59 

60class BaseSender(Base): 

61 is_participant: bool = False 

62 

63 def _send( 

64 self, 

65 stanza: MessageOrPresenceTypeVar, 

66 **send_kwargs: Any, # noqa:ANN401 

67 ) -> MessageOrPresenceTypeVar: 

68 raise NotImplementedError