XEP-0461: use integers for fallback start/end

This commit is contained in:
nicoco 2022-11-22 08:43:53 +01:00
parent a7501abe56
commit 89b1e1e682
2 changed files with 23 additions and 8 deletions

View File

@ -23,13 +23,10 @@ class FeatureFallBack(ElementBase):
start = self["fallback_body"]["start"] start = self["fallback_body"]["start"]
end = self["fallback_body"]["end"] end = self["fallback_body"]["end"]
body = self.parent()["body"] body = self.parent()["body"]
try: if start < end < len(body):
start = int(start)
end = int(end)
except ValueError:
return body
else:
return body[:start] + body[end:] return body[:start] + body[end:]
else:
return body
class FallBackBody(ElementBase): class FallBackBody(ElementBase):
@ -40,6 +37,24 @@ class FallBackBody(ElementBase):
plugin_attrib = "fallback_body" plugin_attrib = "fallback_body"
interfaces = {"start", "end"} 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(): def register_plugins():
register_stanza_plugin(Message, Reply) register_stanza_plugin(Message, Reply)

View File

@ -27,8 +27,8 @@ class TestReply(SlixTest):
message = Message() message = Message()
message["body"] = "12345\nrealbody" message["body"] = "12345\nrealbody"
message["feature_fallback"]["for"] = "NS" message["feature_fallback"]["for"] = "NS"
message["feature_fallback"]["fallback_body"]["start"] = "0" message["feature_fallback"]["fallback_body"]["start"] = 0
message["feature_fallback"]["fallback_body"]["end"] = "6" message["feature_fallback"]["fallback_body"]["end"] = 6
self.check( self.check(
message, message,