XEP-0461: use integers for fallback start/end
This commit is contained in:
parent
a7501abe56
commit
89b1e1e682
2 changed files with 23 additions and 8 deletions
|
@ -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)
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Reference in a new issue