diff --git a/slixmpp/plugins/xep_0461/stanza.py b/slixmpp/plugins/xep_0461/stanza.py index b99b2745..1035fd83 100644 --- a/slixmpp/plugins/xep_0461/stanza.py +++ b/slixmpp/plugins/xep_0461/stanza.py @@ -23,13 +23,10 @@ class FeatureFallBack(ElementBase): start = self["fallback_body"]["start"] end = self["fallback_body"]["end"] body = self.parent()["body"] - try: - start = int(start) - end = int(end) - except ValueError: - return body - else: + if start < end < len(body): return body[:start] + body[end:] + else: + return body class FallBackBody(ElementBase): @@ -40,6 +37,24 @@ class FallBackBody(ElementBase): plugin_attrib = "fallback_body" interfaces = {"start", "end"} + def set_start(self, v: int): + self._set_attr("start", str(v)) + + def get_start(self): + try: + return int(self._get_attr("start")) + except ValueError: + return 0 + + def set_end(self, v: int): + self._set_attr("end", str(v)) + + def get_end(self): + try: + return int(self._get_attr("end")) + except ValueError: + return 0 + def register_plugins(): register_stanza_plugin(Message, Reply) diff --git a/tests/test_stanza_xep_0461.py b/tests/test_stanza_xep_0461.py index b9550481..90aa751b 100644 --- a/tests/test_stanza_xep_0461.py +++ b/tests/test_stanza_xep_0461.py @@ -27,8 +27,8 @@ class TestReply(SlixTest): message = Message() message["body"] = "12345\nrealbody" message["feature_fallback"]["for"] = "NS" - message["feature_fallback"]["fallback_body"]["start"] = "0" - message["feature_fallback"]["fallback_body"]["end"] = "6" + message["feature_fallback"]["fallback_body"]["start"] = 0 + message["feature_fallback"]["fallback_body"]["end"] = 6 self.check( message,