From 64ef0a4561058de4ca7309767e89366bc1c7502f Mon Sep 17 00:00:00 2001 From: Aldo Cortesi Date: Tue, 24 Jul 2012 23:57:18 +1200 Subject: Swap the offset, seconds arguments for the pause operator. This makes it uniform with the other operators.s --- libpathod/rparse.py | 8 ++++---- libpathod/templates/docs_lang.html | 4 ++-- libpathod/templates/docs_pathod.html | 8 ++++---- test/test_pathoc.py | 2 +- test/test_rparse.py | 14 +++++++------- 5 files changed, 18 insertions(+), 18 deletions(-) diff --git a/libpathod/rparse.py b/libpathod/rparse.py index 8b19a1d2..ab657974 100644 --- a/libpathod/rparse.py +++ b/libpathod/rparse.py @@ -413,20 +413,20 @@ class Method: class PauseAt: - def __init__(self, seconds, offset): - self.seconds, self.offset = seconds, offset + def __init__(self, offset, seconds): + self.offset, self.seconds = offset, seconds @classmethod def expr(klass): e = pp.Literal("p").suppress() + e += Offset + e += pp.Literal(",").suppress() e += pp.MatchFirst( [ v_integer, pp.Literal("f") ] ) - e += pp.Literal(",").suppress() - e += Offset return e.setParseAction(lambda x: klass(*x)) def accept(self, settings, r): diff --git a/libpathod/templates/docs_lang.html b/libpathod/templates/docs_lang.html index 4325ef39..9999282d 100644 --- a/libpathod/templates/docs_lang.html +++ b/libpathod/templates/docs_lang.html @@ -66,7 +66,7 @@ - pSECONDS,OFFSET + pOFFSET,SECONDS Pause for SECONDS seconds after OFFSET bytes. SECONDS can be an integer or "f" to pause forever. @@ -135,7 +135,7 @@ - pSECONDS,OFFSET + pOFFSET,SECONDS Pause for SECONDS seconds after OFFSET bytes. SECONDS can be an integer or "f" to pause forever. diff --git a/libpathod/templates/docs_pathod.html b/libpathod/templates/docs_pathod.html index 977642c6..1c8f01c7 100644 --- a/libpathod/templates/docs_pathod.html +++ b/libpathod/templates/docs_pathod.html @@ -92,19 +92,19 @@ various other goodies. Try it by visiting the server root:

for 120 seconds after sending 50 bytes (counted from the first byte of the HTTP response):

-
200:b@1m:p120,50
+
200:b@1m:p50,120

If that's not long enough, we can tell pathod to hang forever:

-
200:b@1m:p120,f
+
200:b@1m:pf,120

Or to send all data, and then hang without disconnecting:

-
200:b@1m:p120,a
+
200:b@1m:pa,120

We can also ask pathod to hang randomly:

-
200:b@1m:pr,a
+
200:b@1m:pr,10

There is a similar mechanism for dropping connections mid-response. So, we can tell pathod to disconnect after sending 50 bytes:

diff --git a/test/test_pathoc.py b/test/test_pathoc.py index 15493e96..3cd07649 100644 --- a/test/test_pathoc.py +++ b/test/test_pathoc.py @@ -31,7 +31,7 @@ class TestDaemon: s = cStringIO.StringIO() c.print_requests( - ["get:'/p/200:p10,0'"], True, True, s + ["get:'/p/200:p0,10'"], True, True, s ) assert "Timeout" in s.getvalue() diff --git a/test/test_rparse.py b/test/test_rparse.py index 634eb6a7..57520176 100644 --- a/test/test_rparse.py +++ b/test/test_rparse.py @@ -226,13 +226,13 @@ class TestPauses: assert v.seconds == 10 assert v.offset == 10 - v = e.parseString("pf,10")[0] + v = e.parseString("p10,f")[0] assert v.seconds == "f" - v = e.parseString("pf,r")[0] + v = e.parseString("pr,f")[0] assert v.offset == "r" - v = e.parseString("pf,a")[0] + v = e.parseString("pa,f")[0] assert v.offset == "a" def test_request(self): @@ -311,15 +311,15 @@ class TestParseResponse: assert utils.get_header("foo", r.headers) def test_parse_pause_before(self): - r = rparse.parse_response({}, "400:p10,0") + r = rparse.parse_response({}, "400:p0,10") assert (0, "pause", 10) in r.actions def test_parse_pause_after(self): - r = rparse.parse_response({}, "400:p10,a") + r = rparse.parse_response({}, "400:pa,10") assert ("a", "pause", 10) in r.actions def test_parse_pause_random(self): - r = rparse.parse_response({}, "400:p10,r") + r = rparse.parse_response({}, "400:pr,10") assert ("r", "pause", 10) in r.actions def test_parse_stress(self): @@ -397,7 +397,7 @@ class TestWriteValues: r.serve(s, None) s = cStringIO.StringIO() - r = rparse.parse_response({}, "400:p0,a") + r = rparse.parse_response({}, "400:pa,0") r.serve(s, None) s = cStringIO.StringIO() -- cgit v1.2.3