1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87
|
import _expect
class popen2:
def __init__ (self, *args):
self.p = apply (_expect.popen2, args)
self.command = _expect.get_command (self.p)
def read (self, *args):
return apply (_expect.read, (self.p,) + args)
def read_error (self, *args):
return apply (_expect.read_stderr, (self.p,) + args)
def write (self, *args):
return apply (_expect.write, (self.p,) + args)
def close (self):
return _expect.close (self.p)
def flush (self):
pass
def isatty (self):
return 0
def readline (self):
return _expect.read (self.p, '\n')
def readlines (self):
r = []
while 1:
l = _expect.read (self.p, '\n')
if not l:
return r
r.append (l)
def seek (self, offset, whence):
if whence != 1:
raise ValueError, "seek: third arg must be 1"
while offset > 0:
if offset > 65536:
offset = offset - len (_expect.read (self.p, 65536))
else:
offset = offset - len (_expect.read (self.p, offset))
def tell (self):
return _expect.get_count (self.p)
def pid (self):
return _expect.get_pid (self.p)
def fds (self):
return (
_expect.get_fd_in (self.p),
_expect.get_fd_out (self.p),
_expect.get_fd_err (self.p)
)
def setblocking (self, block):
_expect.set_blocking (self.p, block)
def settimeout (self, *args):
return apply (_expect.set_timeout, (self.p,) + args)
def writelines (self, t):
for l in t:
return _expect.write (self.p, l)
# we are going to say that __repr__ does not produce and error
def __repr__ (self):
try:
return _expect.read (self.p)
except:
return ""
class popen (popen2):
def __init__ (self, *args):
self.p = apply (_expect.popen, args)
self.command = _expect.get_command (self.p)
class popen3 (popen2):
def __init__ (self, *args):
self.p = apply (_expect.popen3, args)
self.command = _expect.get_command (self.p)
|