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

1from abc import ABC, 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 ...util.types import AnyGateway 

11 

12 

13class Base(ABC): 

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

15 

16 xmpp: "AnyGateway" 

17 

18 jid: JID 

19 name: str | None = None 

20 

21 @property 

22 @abstractmethod 

23 def _uploader(self) -> AttachmentUploader: 

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

25 raise NotImplementedError 

26 

27 session: "AnySession | None" = None 

28 """Session to which this entity belongs 

29 

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

31 """ 

32 

33 

34class SessionBound(Base): 

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

36 

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

38 own behalf rather than on behalf of a user. 

39 """ 

40 

41 session: AnySession 

42 

43 @property 

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

45 return AttachmentUploader(self.xmpp, self.session) 

46 

47 @property 

48 def user_jid(self) -> JID: 

49 return self.session.user_jid 

50 

51 @property 

52 def user_pk(self) -> int: 

53 return self.session.user_pk 

54 

55 

56class BaseSender(Base): 

57 is_participant: bool = False 

58 

59 def _send( 

60 self, 

61 stanza: MessageOrPresenceTypeVar, 

62 **send_kwargs: Any, # noqa:ANN401 

63 ) -> MessageOrPresenceTypeVar: 

64 raise NotImplementedError