From d6ab3124cea389bc72d465cfe7a4306731eaaaa9 Mon Sep 17 00:00:00 2001 From: mathieui Date: Fri, 5 Feb 2021 19:10:52 +0100 Subject: XEP-0084: add integer wrappers for int stanza attributes --- slixmpp/plugins/xep_0084/stanza.py | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/slixmpp/plugins/xep_0084/stanza.py b/slixmpp/plugins/xep_0084/stanza.py index 4b6370ce..57754265 100644 --- a/slixmpp/plugins/xep_0084/stanza.py +++ b/slixmpp/plugins/xep_0084/stanza.py @@ -65,6 +65,35 @@ class Info(ElementBase): plugin_multi_attrib = 'items' interfaces = {'bytes', 'height', 'id', 'type', 'url', 'width'} + def _get_int(self, name: str) -> int: + try: + return int(self._get_attr(name)) + except ValueError: + return 0 + + def _set_int(self, name: str, value: int): + if value not in ('', None): + int(value) + self._set_attr(name, value) + + def get_bytes(self) -> int: + return self._get_int('bytes') + + def _set_bytes(self, value: int): + self._set_int('bytes', value) + + def get_height(self) -> int: + self._get_int('height') + + def set_height(self, value: int): + self._set_int('height', value) + + def get_width(self) -> int: + self._get_int(self, 'width') + + def set_width(self, value: int): + self._set_int('with', value) + class Pointer(ElementBase): name = 'pointer' -- cgit v1.2.3