XEP-0461: add get fallback body helper
This commit is contained in:
parent
7300f1285e
commit
9b89401b36
@ -18,6 +18,16 @@ class FeatureFallBack(ElementBase):
|
|||||||
plugin_attrib = "feature_fallback"
|
plugin_attrib = "feature_fallback"
|
||||||
interfaces = {"for"}
|
interfaces = {"for"}
|
||||||
|
|
||||||
|
def get_fallback_body(self):
|
||||||
|
# only works for a single fallback_body attrib
|
||||||
|
start = self["fallback_body"]["start"]
|
||||||
|
end = self["fallback_body"]["end"]
|
||||||
|
body = self.parent()["body"]
|
||||||
|
if start < end < len(body):
|
||||||
|
return body[start:end]
|
||||||
|
else:
|
||||||
|
return ""
|
||||||
|
|
||||||
def get_stripped_body(self):
|
def get_stripped_body(self):
|
||||||
# only works for a single fallback_body attrib
|
# only works for a single fallback_body attrib
|
||||||
start = self["fallback_body"]["start"]
|
start = self["fallback_body"]["start"]
|
||||||
|
@ -61,5 +61,15 @@ class TestReply(SlixTest):
|
|||||||
"""
|
"""
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def testGetFallBackBody(self):
|
||||||
|
body = "Anna wrote:\nHi, how are you?"
|
||||||
|
quoted = "> Anna wrote:\n> Hi, how are you?\n"
|
||||||
|
|
||||||
|
msg = Message()
|
||||||
|
msg["body"] = "Great"
|
||||||
|
msg["feature_fallback"].add_quoted_fallback(body)
|
||||||
|
body2 = msg["feature_fallback"].get_fallback_body()
|
||||||
|
self.assertTrue(body2 == quoted, body2)
|
||||||
|
|
||||||
|
|
||||||
suite = unittest.TestLoader().loadTestsFromTestCase(TestReply)
|
suite = unittest.TestLoader().loadTestsFromTestCase(TestReply)
|
||||||
|
Loading…
Reference in New Issue
Block a user