diff --git a/libpathod/rparse.py b/libpathod/rparse.py index 968173047..8b19a1d23 100644 --- a/libpathod/rparse.py +++ b/libpathod/rparse.py @@ -86,6 +86,15 @@ def write_values(fp, vals, actions, sofar=0, skip=0, blocksize=BLOCKSIZE): send_chunk(fp, a[2], blocksize, 0, len(a[2])) send_chunk(fp, v, blocksize, offset, len(v)) sofar += len(v) + # Remainders + while actions: + a = actions.pop() + if a[1] == "pause": + time.sleep(a[2]) + elif a[1] == "disconnect": + return True + elif a[1] == "inject": + send_chunk(fp, a[2], blocksize, 0, len(a[2])) except tcp.NetLibDisconnect: # pragma: no cover return True @@ -434,12 +443,7 @@ class DisconnectAt: @classmethod def expr(klass): e = pp.Literal("d").suppress() - e += e + pp.MatchFirst( - [ - v_integer, - pp.Literal("r") - ] - ) + e += Offset return e.setParseAction(lambda x: klass(*x)) diff --git a/test/test_rparse.py b/test/test_rparse.py index dadf5bc1a..634eb6a7c 100644 --- a/test/test_rparse.py +++ b/test/test_rparse.py @@ -391,6 +391,20 @@ class TestWriteValues: rparse.write_values(s, tst[:], [(1, "pause", 0)], blocksize=i) assert s.getvalue() == "".join(tst) + def test_write_values_after(self): + s = cStringIO.StringIO() + r = rparse.parse_response({}, "400:da") + r.serve(s, None) + + s = cStringIO.StringIO() + r = rparse.parse_response({}, "400:p0,a") + r.serve(s, None) + + s = cStringIO.StringIO() + r = rparse.parse_response({}, "400:ia,'xx'") + r.serve(s, None) + assert s.getvalue().endswith('xx') + def test_ready_actions(): x = [(0, 5)]