From 8e0c01ae39f2f1f80ad0d372119e8654de21d29c Mon Sep 17 00:00:00 2001 From: Aldo Cortesi Date: Fri, 20 Jul 2012 23:47:34 +1200 Subject: [PATCH] Fine-tuning for injection: docs, bugfixes. --- libpathod/rparse.py | 11 +++++++++-- libpathod/templates/docs_pathod.html | 11 +++++++++++ test/test_rparse.py | 9 +++++++++ 3 files changed, 29 insertions(+), 2 deletions(-) diff --git a/libpathod/rparse.py b/libpathod/rparse.py index 5a2f84b12..e71265eac 100644 --- a/libpathod/rparse.py +++ b/libpathod/rparse.py @@ -421,7 +421,8 @@ class InjectAt: e = e + pp.MatchFirst( [ v_integer, - pp.Literal("r") + pp.Literal("r"), + pp.Literal("a") ] ) e += pp.Literal(",").suppress() @@ -429,7 +430,13 @@ class InjectAt: return e.setParseAction(lambda x: klass(*x)) def accept(self, settings, r): - r.actions.append((self.offset, "inject", self.value)) + r.actions.append( + ( + self.offset, + "inject", + self.value.get_generator(settings) + ) + ) class Header: diff --git a/libpathod/templates/docs_pathod.html b/libpathod/templates/docs_pathod.html index 1527f851e..8fc062caa 100644 --- a/libpathod/templates/docs_pathod.html +++ b/libpathod/templates/docs_pathod.html @@ -157,6 +157,17 @@ various other goodies. Try it by visiting the server root:

+ + + iOFFSET,VALUE + + + Inject the specified value at the offset. OFFSET can be an + integer, or "r" to generate a random offset or "a" for an + offset just after all data has been sent. + + + lVALUE diff --git a/test/test_rparse.py b/test/test_rparse.py index 04a4972f5..dfc8c7589 100644 --- a/test/test_rparse.py +++ b/test/test_rparse.py @@ -175,6 +175,10 @@ class TestInject: assert a[0] == "r" assert a[1] == "inject" + a = rparse.parse_response({}, "400:ia,@100").actions[0] + assert a[0] == "a" + assert a[1] == "inject" + def test_at(self): e = rparse.InjectAt.expr() v = e.parseString("i0,'foo'")[0] @@ -185,6 +189,11 @@ class TestInject: v = e.parseString("ir,'foo'")[0] assert v.offset == "r" + def test_serve(self): + s = cStringIO.StringIO() + r = rparse.parse_response({}, "400:i0,'foo'") + assert r.serve(s) + class TestShortcuts: def test_parse_response(self):