(self)
return {
            'output_streams': output_streams,
            'input_streams': input_streams,
        }
Determine which i/o streams to attach.
Determine which i/o streams to attach.
Determine which i / o streams to attach .
def _get_redirects(self):
        """Determine which i/o streams to attach."""
        input_streams, output_streams = [], []
        # explicit redirects
        # input redirects
        infile_params = self.get('input').split(u':')
        if infile_params[0].upper() in (u'STDIO', u'STDIN'):
            if u'RAW' in (_x.upper() for _x in infile_params):
                input_streams.append(stdio.stdin.buffer)
            else:
                input_streams.append(stdio.stdin)
        else:
            if len(infile_params) > 1 and infile_params[0].upper() == u'FILE':
                infile = infile_params[1]
            else:
                infile = infile_params[0]
            if infile:
                try:
                    input_streams.append(io.open(infile, 'rb'))
                except EnvironmentError as e:
                    logging.warning(u'Could not open input file `%s`: %s', infile, e.strerror)
        # output redirects
        outfile_params = self.get('output').split(u':')
        if outfile_params[0].upper() in (u'STDIO', u'STDOUT'):
            if u'RAW' in (_x.upper() for _x in outfile_params):
                output_streams.append(stdio.stdout.buffer)
            else:
                output_streams.append(stdio.stdout)
        else:
            if len(outfile_params) > 1 and outfile_params[0].upper() == u'FILE':
                outfile_params = outfile_params[1:]
            outfile = outfile_params[0]
            append = len(outfile_params) > 1 and outfile_params[1].lower() == u'append'
            if outfile:
                try:
                    output_streams.append(io.open(outfile, 'ab' if append else 'wb'))
                except EnvironmentError as e:
                    logging.warning(u'Could not open output file `%s`: %s', outfile, e.strerror)
        # implicit stdio redirects
        # add stdio if redirected or no interface
        if stdio.stdin not in input_streams and stdio.stdin.buffer not in input_streams:
            if IS_CONSOLE_APP and not stdio.stdin.isatty():
                # redirected on console; use bytes stream
                input_streams.append(stdio.stdin.buffer)
            elif IS_CONSOLE_APP and not self.interface:
                # no interface & on console; use unicode stream
                input_streams.append(stdio.stdin)
        # redirect output as well if input is redirected, but not the other way around
        # this is because (1) GW-BASIC does this from the DOS prompt
        # (2) otherwise we don't see anything - we quit after input closes
        # isatty is also false if we run as a GUI exe, so check that here
        if stdio.stdout not in output_streams and stdio.stdout.buffer not in output_streams:
            if IS_CONSOLE_APP and (not stdio.stdout.isatty() or not stdio.stdin.isatty()):
                output_streams.append(stdio.stdout.buffer)
            elif IS_CONSOLE_APP and not self.interface:
                output_streams.append(stdio.stdout)
        return {
            'output_streams': output_streams,
            'input_streams': input_streams,
        }
def _get_redirects ( self ) : input_streams , output_streams = [ ] , [ ] # explicit redirects # input redirects infile_params = self . get ( 'input' ) . split ( u':' ) if infile_params [ 0 ] . upper ( ) in ( u'STDIO' , u'STDIN' ) : if u'RAW' in ( _x . upper ( ) for _x in infile_params ) : input_streams . append ( stdio . stdin . buffer ) else : input_streams . append ( stdio . stdin ) else : if len ( infile_params ) > 1 and infile_params [ 0 ] . upper ( ) == u'FILE' : infile = infile_params [ 1 ] else : infile = infile_params [ 0 ] if infile : try : input_streams . append ( io . open ( infile , 'rb' ) ) except EnvironmentError as e : logging . warning ( u'Could not open input file `%s`: %s' , infile , e . strerror ) # output redirects outfile_params = self . get ( 'output' ) . split ( u':' ) if outfile_params [ 0 ] . upper ( ) in ( u'STDIO' , u'STDOUT' ) : if u'RAW' in ( _x . upper ( ) for _x in outfile_params ) : output_streams . append ( stdio . stdout . buffer ) else : output_streams . append ( stdio . stdout ) else : if len ( outfile_params ) > 1 and outfile_params [ 0 ] . upper ( ) == u'FILE' : outfile_params = outfile_params [ 1 : ] outfile = outfile_params [ 0 ] append = len ( outfile_params ) > 1 and outfile_params [ 1 ] . lower ( ) == u'append' if outfile : try : output_streams . append ( io . open ( outfile , 'ab' if append else 'wb' ) ) except EnvironmentError as e : logging . warning ( u'Could not open output file `%s`: %s' , outfile , e . strerror ) # implicit stdio redirects # add stdio if redirected or no interface if stdio . stdin not in input_streams and stdio . stdin . buffer not in input_streams : if IS_CONSOLE_APP and not stdio . stdin . isatty ( ) : # redirected on console; use bytes stream input_streams . append ( stdio . stdin . buffer ) elif IS_CONSOLE_APP and not self . interface : # no interface & on console; use unicode stream input_streams . append ( stdio . stdin ) # redirect output as well if input is redirected, but not the other way around # this is because (1) GW-BASIC does this from the DOS prompt # (2) otherwise we don't see anything - we quit after input closes # isatty is also false if we run as a GUI exe, so check that here if stdio . stdout not in output_streams and stdio . stdout . buffer not in output_streams : if IS_CONSOLE_APP and ( not stdio . stdout . isatty ( ) or not stdio . stdin . isatty ( ) ) : output_streams . append ( stdio . stdout . buffer ) elif IS_CONSOLE_APP and not self . interface : output_streams . append ( stdio . stdout ) return { 'output_streams' : output_streams , 'input_streams' : input_streams , }