def __init__(self, first, last=None):
"""'first' is a Popen object. 'last', if given, is another
Popen object that is the end of the joints to 'first'.
'write' operations send data to first's stdin and 'read'
operations get data from last's stdout/stderr.
"""
if not last:
last = first
self.first = first
self.last = last
if platform.system() == 'Windows':
if not isinstance(first, Popen) or not isinstance(last, Popen):
raise ValueError('argument must be asyncfile.Popen object')
if first.stdin:
self.stdin = first.stdin
else:
self.stdin = None
if last.stdout:
self.stdout = last.stdout
else:
self.stdout = None
if last.stderr:
self.stderr = last.stderr
else:
self.stderr = None
else:
if not isinstance(first, subprocess.Popen) or not isinstance(last, subprocess.Popen):
raise ValueError('argument must be subprocess.Popen object')
if first.stdin:
self.stdin = AsyncFile(first.stdin)
else:
self.stdin = None
if last.stdout:
self.stdout = AsyncFile(last.stdout)
else:
self.stdout = None
if last.stderr:
self.stderr = AsyncFile(last.stderr)
else:
self.stderr = None
评论列表
文章目录