Make actions at end of message work.

This commit is contained in:
Aldo Cortesi 2012-07-24 23:49:58 +12:00
parent 8f0ebb405d
commit cb09488dc8
2 changed files with 24 additions and 6 deletions

View File

@ -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, a[2], blocksize, 0, len(a[2]))
send_chunk(fp, v, blocksize, offset, len(v)) send_chunk(fp, v, blocksize, offset, len(v))
sofar += 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 except tcp.NetLibDisconnect: # pragma: no cover
return True return True
@ -434,12 +443,7 @@ class DisconnectAt:
@classmethod @classmethod
def expr(klass): def expr(klass):
e = pp.Literal("d").suppress() e = pp.Literal("d").suppress()
e += e + pp.MatchFirst( e += Offset
[
v_integer,
pp.Literal("r")
]
)
return e.setParseAction(lambda x: klass(*x)) return e.setParseAction(lambda x: klass(*x))

View File

@ -391,6 +391,20 @@ class TestWriteValues:
rparse.write_values(s, tst[:], [(1, "pause", 0)], blocksize=i) rparse.write_values(s, tst[:], [(1, "pause", 0)], blocksize=i)
assert s.getvalue() == "".join(tst) 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(): def test_ready_actions():
x = [(0, 5)] x = [(0, 5)]