How to implement the expect function in embedding python ?
Larf
larf at 263.net
Mon Jan 8 08:23:55 EST 2001
Hello!
I have written a telnet client program with C++, and now trying to embed python as the script language. I've written a extend module so now people can access the screen buffer and send characters in python script files. It works very fine. But I hope add some functions just like expect in Tcl. For example, I want people can write scripts like below:
---------------------
import miniterm
b = miniterm.buffer # screen buffer
send = miniterm.send()
send('a') # send some chars
if miniterm.expect( condition, timeout ):
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^???
for i in range( len(b) ):
print b[i]
else:
miniterm.disconnect()
..
..
---------------------
When the function 'miniterm.expect' was called, the telnet program should run normally until the certain condition achieved, then the control should return to the script. Now I wonder how can I implement this function? Should I reimplement a select loop in the function itself? Or use one process run the telnet and another process to monitor it and use pty to communicate like expect? Or maybe threads will be better choices? I have no experiences in embedding scripts programming , so any advice are very appreciated. Thanks!
Best regards
Kafa
More information about the Python-list
mailing list