XEP-0084: add integer wrappers for int stanza attributes

This commit is contained in:
mathieui 2021-02-05 19:10:52 +01:00
parent cb8d2edc8d
commit d6ab3124ce

View file

@ -65,6 +65,35 @@ class Info(ElementBase):
plugin_multi_attrib = 'items' plugin_multi_attrib = 'items'
interfaces = {'bytes', 'height', 'id', 'type', 'url', 'width'} 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): class Pointer(ElementBase):
name = 'pointer' name = 'pointer'