X-Git-Url: https://git.phdru.name/?a=blobdiff_plain;f=subproc.py;h=1828b1c240151e1df7d8a3d8d809e912f6820c6f;hb=a7daaf8f136d162109a5541a98f44991855628cc;hp=3507ac1b86a123718b2133d5e63fe89303be43e0;hpb=97202bf84e9c78d8fac912a82a85fb1cbb233a4b;p=bookmarks_db.git diff --git a/subproc.py b/subproc.py index 3507ac1..1828b1c 100644 --- a/subproc.py +++ b/subproc.py @@ -16,7 +16,7 @@ Subprocess class features: __version__ = "Revision: 1.15 " -# Id: subproc.py,v 1.15 1998/12/14 20:53:16 klm Exp +# Id: subproc.py,v 1.15 1998/12/14 20:53:16 klm Exp # Originally by ken manheimer, ken.manheimer@nist.gov, jan 1995. # Prior art: Initially based python code examples demonstrating usage of pipes @@ -40,6 +40,9 @@ __version__ = "Revision: 1.15 " # # ken.manheimer@nist.gov +# This is a modified version by Oleg Broytman . +# The original version is still preserved at +# https://www.python.org/ftp/python/contrib-09-Dec-1999/System/subproc.tar.gz import sys, os, string, time, types import select @@ -206,7 +209,7 @@ class Subprocess: got0 = self.readPendingChars(n) got = got + got0 n = n - len(got0) - return got + return got def readPendingChars(self, max=None): """Read all currently pending subprocess output as a single string.""" return self.readbuf.readPendingChars(max) @@ -325,7 +328,7 @@ class Subprocess: # Only got here if subprocess is not gone: raise SubprocessError( "Failed kill of subproc %d, '%s', with signals %s" % - (self.pid, self.cmd, map(lambda(x): x[0], sigs))) + (self.pid, self.cmd, map(lambda x: x[0], sigs))) def __del__(self): """Terminate the subprocess""" @@ -401,15 +404,15 @@ class ReadBuf: got = "" if self.buf: - if (max > 0) and (len(self.buf) > max): - got = self.buf[0:max] - self.buf = self.buf[max:] - else: - got, self.buf = self.buf, '' - return got + if (max > 0) and (len(self.buf) > max): + got = self.buf[0:max] + self.buf = self.buf[max:] + else: + got, self.buf = self.buf, '' + return got if self.eof: - return '' + return '' sel = select.select([self.fd], [], [self.fd], 0) if sel[2]: @@ -537,7 +540,7 @@ def record_trial(s): c.write(s) c.seek(0) r = c.read() - show = " start:\t %s\n end:\t %s\n" % (`s`, `r`) + show = " start:\t %s\n end:\t %s\n" % (repr(s), repr(r)) if r != s: raise IOError("String distorted:\n%s" % show) @@ -590,7 +593,7 @@ class Ph: line = string.splitfields(line, ':') it[string.strip(line[0])] = ( string.strip(string.join(line[1:]))) - + def getreply(self): """Consume next response from ph, returning list of lines or string err.""" @@ -654,12 +657,12 @@ def test(p=0): print("\t...yep, it failed.") print('\tWrite, then read, two newline-teriminated lines, using readline:') p.write('first full line written\n'); p.write('second.\n') - print(`p.readline()`) - print(`p.readline()`) + print(repr(p.readline())) + print(repr(p.readline())) print('\tThree lines, last sans newline, read using combination:') p.write('first\n'); p.write('second\n'); p.write('third, (no cr)') print('\tFirst line via readline:') - print(`p.readline()`) + print(repr(p.readline())) print('\tRest via readPendingChars:') print(p.readPendingChars()) print("\tStopping then continuing subprocess (verbose):")