(self, native_name, filetype, mode)
Open a stream on disk by os-native name with BASIC mode and access level.
Open a stream on disk by os-native name with BASIC mode and access level.
Open a stream on disk by os - native name with BASIC mode and access level .
def open_stream(self, native_name, filetype, mode):
        """Open a stream on disk by os-native name with BASIC mode and access level."""
        try:
            # create file if in RANDOM or APPEND mode and doesn't exist yet
            # OUTPUT mode files are created anyway since they're opened with wb
            if ((mode == b'A' or mode == b'R') and not os.path.exists(native_name)):
                io.open(native_name, 'wb').close()
            if mode == b'A':
                f = io.open(native_name, 'r+b')
                # APPEND mode is only valid for text files (which are seekable);
                # first cut off EOF byte, if any.
                try:
                    f.seek(-1, 2)
                    if f.read(1) == b'\x1a':
                        f.seek(-1, 1)
                        f.truncate()
                except EnvironmentError:
                    pass
                f.close()
            access_mode = ACCESS_MODES[mode]
            text_mode = self._text_mode
            # access 'raw' text files as bytes
            if not text_mode:
                return io.open(native_name, access_mode + 'b')
            # encoded text files
            # use a BOM on input and output, but not append
            if text_mode.lower() in UTF_8:
                text_mode = 'utf-8-sig'
            # preserve original newlines on reading and writing
            return io.open(
                native_name, access_mode, encoding=text_mode, errors='replace', newline=''
            )
        except EnvironmentError as e:
            handle_oserror(e)
        except TypeError:
            # TypeError: stat() argument 1 must be encoded string without null bytes, not str
            # bad file number, which is what GW throws for open chr$(0)
            raise error.BASICError(error.BAD_FILE_NUMBER)
def open_stream ( self , native_name , filetype , mode ) : try : # create file if in RANDOM or APPEND mode and doesn't exist yet # OUTPUT mode files are created anyway since they're opened with wb if ( ( mode == b'A' or mode == b'R' ) and not os . path . exists ( native_name ) ) : io . open ( native_name , 'wb' ) . close ( ) if mode == b'A' : f = io . open ( native_name , 'r+b' ) # APPEND mode is only valid for text files (which are seekable); # first cut off EOF byte, if any. try : f . seek ( - 1 , 2 ) if f . read ( 1 ) == b'\x1a' : f . seek ( - 1 , 1 ) f . truncate ( ) except EnvironmentError : pass f . close ( ) access_mode = ACCESS_MODES [ mode ] text_mode = self . _text_mode # access 'raw' text files as bytes if not text_mode : return io . open ( native_name , access_mode + 'b' ) # encoded text files # use a BOM on input and output, but not append if text_mode . lower ( ) in UTF_8 : text_mode = 'utf-8-sig' # preserve original newlines on reading and writing return io . open ( native_name , access_mode , encoding = text_mode , errors = 'replace' , newline = '' ) except EnvironmentError as e : handle_oserror ( e ) except TypeError : # TypeError: stat() argument 1 must be encoded string without null bytes, not str # bad file number, which is what GW throws for open chr$(0) raise error . BASICError ( error . BAD_FILE_NUMBER )