diff --git a/demo/dualftp.py b/demo/dualftp.py index e6a54c292a58ddac6813dc750dedd3cc1e167532..e2cff3ecfbbfffa74643a1d7f394405ba7a40680 100644 --- a/demo/dualftp.py +++ b/demo/dualftp.py @@ -6,10 +6,14 @@ # # This also tests the expect_after functionality. +import sys +import time + import pcl_expect pcl_expect.stty_init = "-onlcr -ocrnl -echo" +time0 = time.time() funet = pcl_expect.spawn("ftp ftp.funet.fi") sunet = pcl_expect.spawn("ftp ftp.sunet.se") @@ -25,6 +29,8 @@ cmds = {} cmds[funet] = ["cd pub\n", "passive\n", "dir\n"] cmds[sunet] = ["cd pub\n", "passive\n", "dir\n"] +speed = {} + printed = 0 def prompt_cb(ftp): global printed @@ -35,6 +41,7 @@ def prompt_cb(ftp): else: print ftp.match.group() printed += 1 + speed[ftp] = time.time() - time0 pcl_expect.debug("STATE: cmds[sunet] = %s\n" % cmds[sunet]) pcl_expect.debug("STATE: cmds[funet] = %s\n" % cmds[funet]) @@ -51,7 +58,11 @@ pcl_expect.expect_after([(pcl_expect.RE, funet, "Name.*:", name_cb), x = pcl_expect.impl() while x.loop(): - pass + if x.timeout(): + sys.stdout.write(".") + sys.stdout.flush() + x.cont() + continue sunet.send("bye\n") funet.send("bye\n") @@ -63,9 +74,22 @@ while x.loop(): if x.eof(sunet): print "SUNET final output:", sunet.match sunet.close() + elif x.timeout(): + sys.stdout.write(".") + sys.stdout.flush() + x.cont() + continue x = pcl_expect.impl() while x.loop(): if x.eof(funet): print "FUNET final output:", funet.match funet.close() + elif x.timeout(): + sys.stdout.write(".") + sys.stdout.flush() + x.cont() + continue + +print "SUNET time:", speed[sunet], "seconds" +print "FUNET time:", speed[funet], "seconds"