Make previews safer by stripping pauses.

This commit is contained in:
Aldo Cortesi 2012-07-24 22:38:48 +12:00
parent e9de11f0e3
commit 6c565e778f
3 changed files with 13 additions and 0 deletions

View File

@ -90,6 +90,7 @@ def preview():
return render("preview.html", **args) return render("preview.html", **args)
s = cStringIO.StringIO() s = cStringIO.StringIO()
r.preview_safe()
r.serve(s, check=app.config["pathod"].check_size) r.serve(s, check=app.config["pathod"].check_size)
args["output"] = utils.escape_unprintables(s.getvalue()) args["output"] = utils.escape_unprintables(s.getvalue())
return render("preview.html", **args) return render("preview.html", **args)

View File

@ -527,6 +527,12 @@ class Message:
l += len(self.body) l += len(self.body)
return l return l
def preview_safe(self):
"""
Modify this message to be safe for previews.
"""
self.actions = [i for i in self.actions if i[1] != "pause"]
def effective_length(self, actions): def effective_length(self, actions):
""" """
Calculate the length of the base message with all applied actions. Calculate the length of the base message with all applied actions.

View File

@ -493,6 +493,12 @@ class TestResponse:
r.actions = actions r.actions = actions
testlen(r, actions) testlen(r, actions)
def test_render(self):
r = rparse.parse_response({}, "400:p0,100:dr")
assert r.actions[0][1] == "pause"
r.preview_safe()
assert not r.actions[0][1] == "pause"
def test_read_file(): def test_read_file():