Coverage for slidge/slixfix/xep_0264/stanza.py: 75%

24 statements  

« prev     ^ index     » next       coverage.py v7.6.1, created at 2024-11-07 05:11 +0000

1from typing import Optional 

2 

3from slixmpp import register_stanza_plugin 

4from slixmpp.plugins.xep_0234.stanza import File 

5from slixmpp.xmlstream import ElementBase 

6 

7NS = "urn:xmpp:thumbs:1" 

8 

9 

10class Thumbnail(ElementBase): 

11 name = plugin_attrib = "thumbnail" 

12 namespace = NS 

13 interfaces = {"uri", "media-type", "width", "height"} 

14 

15 def get_width(self) -> float: 

16 return _int_or_none(self._get_attr("width")) 

17 

18 def get_height(self) -> float: 

19 return _int_or_none(self._get_attr("height")) 

20 

21 def set_width(self, v: int) -> None: 

22 self._set_attr("width", str(v)) 

23 

24 def set_height(self, v: int) -> None: 

25 self._set_attr("height", str(v)) 

26 

27 

28def _int_or_none(v) -> Optional[int]: 

29 try: 

30 return int(v) 

31 except ValueError: 

32 return None 

33 

34 

35def register_plugin(): 

36 register_stanza_plugin(File, Thumbnail)