(
            self, fhandle, filetype, mode, number=0,
            field=None, reclen=128, seg=0, offset=0, length=0
        )
Create disk file object of requested type.
Create disk file object of requested type.
Create disk file object of requested type .
def _create_file_object(
            self, fhandle, filetype, mode, number=0,
            field=None, reclen=128, seg=0, offset=0, length=0
        ):
        """Create disk file object of requested type."""
        # determine file type if needed
        if len(filetype) > 1 and mode == b'I':
            # read magic
            first = fhandle.read(1)
            fhandle.seek(0)
            try:
                filetype_found = devicebase.MAGIC_TO_TYPE[first]
                if filetype_found not in filetype:
                    raise error.BASICError(error.BAD_FILE_MODE)
                filetype = filetype_found
            except KeyError:
                filetype = b'A'
        # unicode or bytes input for text & ascii-program files
        # not for random-access files
        if filetype in b'DA':
            if mode in (b'O', b'A'):
                # if the input stream is unicode: decode codepage bytes
                fhandle = self._codepage.wrap_output_stream(
                    fhandle, preserve=CONTROL+(b'\x1A',)
                )
            elif mode == b'I':
                # if the input stream is unicode: encode codepage bytes
                # replace newlines with \r in text mode
                fhandle = self._codepage.wrap_input_stream(
                    fhandle, replace_newlines=not self._soft_linefeed
                )
        if filetype in b'BPM':
            # binary [B]LOAD, [B]SAVE
            return BinaryFile(fhandle, filetype, number, mode, seg, offset, length, self._locks)
        elif filetype == b'A':
            # ascii program file
            return TextFile(fhandle, filetype, number, mode, self._locks)
        elif filetype == b'D':
            if mode in b'IAO':
                # data file for input, output, append
                return TextFile(fhandle, filetype, number, mode, self._locks)
            else:
                # data file for random
                return RandomFile(fhandle, number, field, reclen, self._locks)
        else:
            # incorrect file type requested
            msg = b'Incorrect file type %s requested for mode %s' % (filetype, mode)
            raise ValueError(msg)
def _create_file_object ( self , fhandle , filetype , mode , number = 0 , field = None , reclen = 128 , seg = 0 , offset = 0 , length = 0 ) : # determine file type if needed if len ( filetype ) > 1 and mode == b'I' : # read magic first = fhandle . read ( 1 ) fhandle . seek ( 0 ) try : filetype_found = devicebase . MAGIC_TO_TYPE [ first ] if filetype_found not in filetype : raise error . BASICError ( error . BAD_FILE_MODE ) filetype = filetype_found except KeyError : filetype = b'A' # unicode or bytes input for text & ascii-program files # not for random-access files if filetype in b'DA' : if mode in ( b'O' , b'A' ) : # if the input stream is unicode: decode codepage bytes fhandle = self . _codepage . wrap_output_stream ( fhandle , preserve = CONTROL + ( b'\x1A' , ) ) elif mode == b'I' : # if the input stream is unicode: encode codepage bytes # replace newlines with \r in text mode fhandle = self . _codepage . wrap_input_stream ( fhandle , replace_newlines = not self . _soft_linefeed ) if filetype in b'BPM' : # binary [B]LOAD, [B]SAVE return BinaryFile ( fhandle , filetype , number , mode , seg , offset , length , self . _locks ) elif filetype == b'A' : # ascii program file return TextFile ( fhandle , filetype , number , mode , self . _locks ) elif filetype == b'D' : if mode in b'IAO' : # data file for input, output, append return TextFile ( fhandle , filetype , number , mode , self . _locks ) else : # data file for random return RandomFile ( fhandle , number , field , reclen , self . _locks ) else : # incorrect file type requested msg = b'Incorrect file type %s requested for mode %s' % ( filetype , mode ) raise ValueError ( msg )