def __collect_from_stream(stream, buffer, echo_stream):
 collected = []
 try:
  while True:
   got = os.read(stream.fileno(), 1)
   if (not got):
    break
   collected.append(got)
   if echo_stream:
    echo_stream.write(got)
    echo_stream.flush()
 except OSError:
  pass
 if collected:
  buffer.append(''.join(collected))
 return len(collected)

def __collect_from_stream ( stream , buffer , echo_stream ) : collected = [ ] try : while True : got = os . read ( stream . fileno ( ) , 1 ) if ( not got ) : break collected . append ( got ) if echo_stream : echo_stream . write ( got ) echo_stream . flush ( ) except OSError : pass if collected : buffer . append ( '' . join ( collected ) ) return len ( collected )
read all the input from a stream .