(stream)
Read all available characters from a stream; nonblocking; None if closed.
Read all available characters from a stream; nonblocking; None if closed.
Read all available characters from a stream ; nonblocking ; None if closed .
def read_all_available(stream):
    """Read all available characters from a stream; nonblocking; None if closed."""
    # are we're reading from (wrapped) stdin or not?
    if hasattr(stream, 'isatty') and stream.isatty():
        # this is shaky - try to identify unicode vs bytes stream
        is_unicode_stream = hasattr(stream, 'buffer')
        unistr = console.read_all_chars()
        if is_unicode_stream or unistr is None:
            return unistr
        else:
            return unistr.encode(stdio.stdin.encoding, 'replace')
    else:
        # this would work on unix too
        # just read the whole file and be done with it
        return stream.read() or None
def read_all_available ( stream ) : # are we're reading from (wrapped) stdin or not? if hasattr ( stream , 'isatty' ) and stream . isatty ( ) : # this is shaky - try to identify unicode vs bytes stream is_unicode_stream = hasattr ( stream , 'buffer' ) unistr = console . read_all_chars ( ) if is_unicode_stream or unistr is None : return unistr else : return unistr . encode ( stdio . stdin . encoding , 'replace' ) else : # this would work on unix too # just read the whole file and be done with it return stream . read ( ) or None