diff options
author | noah <noah@656d521f-e311-0410-88e0-e7920216d269> | 2002-09-20 17:32:50 +0000 |
---|---|---|
committer | noah <noah@656d521f-e311-0410-88e0-e7920216d269> | 2002-09-20 17:32:50 +0000 |
commit | 52813853bf50dd9f9e0cde9e2cf3663921991f39 (patch) | |
tree | 525add7a9c8b5ae5aadc31cf8eaeddc798e39668 | |
parent | 4223b00fd1072bac46aa1eefca7b64d97c27eae3 (diff) | |
download | pexpect-52813853bf50dd9f9e0cde9e2cf3663921991f39.tar.gz |
Tightened up the doc strings and made send and write methods
return the number of byte actually written.
git-svn-id: http://pexpect.svn.sourceforge.net/svnroot/pexpect/trunk@71 656d521f-e311-0410-88e0-e7920216d269
-rw-r--r-- | pexpect/pexpect.py | 40 | ||||
-rwxr-xr-x | pexpect/websync | 4 |
2 files changed, 21 insertions, 23 deletions
diff --git a/pexpect/pexpect.py b/pexpect/pexpect.py index 2e7659b..93a7d18 100644 --- a/pexpect/pexpect.py +++ b/pexpect/pexpect.py @@ -378,7 +378,7 @@ class spawn: If a log file was opened using log_open() then all data will also be written to the log file. - Note that if this method is called with timeout=None + Notice that if this method is called with timeout=None then it actually may block. This is a non-blocking wrapper around os.read(). It uses select.select() to supply a timeout. @@ -405,30 +405,32 @@ class spawn: raise ExceptionPexpect('Reached an unexpected state in read().') def write(self, text): - """This is an alias for send().""" - self.send (text) + """This is an alias for send(). + This return the number of bytes actually written. + """ + return self.send (text) def writelines (self, sequence): + """This calls write() for each element in the sequence. + This return the number of bytes actually written. + """ + total_n = 0 for str in sequence: - self.write (str) + total_n = total_n + self.write (str) + return total_n def send(self, text): """This sends a string to the child process. + This return the number of bytes actually written. """ - try: - if text == EOF: - self.senf_eof - - os.write(self.child_fd, text) - except Exception, e: - msg = 'Exception caught in send(): %s' % str(e) - raise ExceptionPexpect(msg) + return os.write(self.child_fd, text) def sendline(self, text): """This is like send(), but it adds a line separator. + This return the number of bytes actually written. """ - self.send(text) - self.send(os.linesep) + n = self.send(text) + return n + self.send(os.linesep) def send_eof(self): """This sends an EOF to the child. @@ -439,14 +441,10 @@ class spawn: line, the read() in the user program returns 0, which signifies end-of-file. - This means: do make this work as expected send_eof() has to be - called at the begining of a line. A newline-charakter is _not_ + This means: to make this work as expected a send_eof() has to be + called at the begining of a line. A newline character is not send here to avoid problems. """ - ### Known Bug: this should either get the EOF character from - ### termios or set (and restore) it. Currently the character - ### is hard-coded here. - ### EOF = '\004' ### Hmmm... how do I send an EOF? ###C if ((m = write(pty, *buf, p - *buf)) < 0) ###C return (errno == EWOULDBLOCK) ? n : -1; @@ -459,7 +457,7 @@ class spawn: try: # EOF is recognized when ICANON is set, thus ensure it is: termios.tcsetattr(fd, termios.TCSADRAIN, new) - os.write(self.child_fd, termios.CEOF) ### This was based from EOF = '\004' + os.write(self.child_fd, termios.CEOF) finally: termios.tcsetattr(fd, termios.TCSADRAIN, old) # restore state diff --git a/pexpect/websync b/pexpect/websync index a8e4e17..6ba4088 100755 --- a/pexpect/websync +++ b/pexpect/websync @@ -6,6 +6,6 @@ # The Vaults of Parnasus which requires a direct URL link to a # tar ball distribution. I don't advertise the package this way. ssh noah@use-pr-shell1.sourceforge.net "cd htdocs;rm index.html;wget http://www.noah.org/python/pexpect/index.html" -scp doc.tgz noah@use-pr-shell1.sourceforge.net:htdocs/doc.tgz -ssh noah@use-pr-shell1.sourceforge.net "cd htdocs;tar zxvf doc.tgz" +scp pexpect-doc.tgz noah@use-pr-shell1.sourceforge.net:htdocs/pexpect-doc.tgz +ssh noah@use-pr-shell1.sourceforge.net "cd htdocs;tar zxvf pexpect-doc.tgz" scp pexpect-current.tgz noah@use-pr-shell1.sourceforge.net:htdocs/pexpect-current.tgz |