(
            self, number, filespec, filetype, mode, access, lock,
            reclen, seg, offset, length, field
        )
Open a file on a disk drive.
Open a file on a disk drive.
Open a file on a disk drive .
def open(
            self, number, filespec, filetype, mode, access, lock,
            reclen, seg, offset, length, field
        ):
        """Open a file on a disk drive."""
        # parse the file spec to a definite native name
        if not self._native_root:
            # undefined disk drive: path not found
            raise error.BASICError(error.PATH_NOT_FOUND)
        # set default extension for programs
        if set(filetype).intersection(set(b'MPBA')):
            defext = b'BAS'
        else:
            defext = b''
        # translate the file name to something DOS-ish if necessary
        if mode == b'I':
            native_name = self._get_native_abspath(filespec, defext, isdir=False, create=False)
        else:
            # random files: try to open matching file
            # if it doesn't exist, use an all-caps 8.3 file name
            native_name = self._get_native_abspath(filespec, defext, isdir=False, create=True)
        # handle locks, open stream and create file object
        # don't open output or append files more than once
        # whether it's the same file is determined by DOS basename, i.e. excluding directories!
        dos_basename = self._get_dos_name_defext(filespec, defext)
        # obtain a lock
        self._locks.open_file(dos_basename, number, mode, lock, access)
        try:
            # open the underlying stream
            fhandle = self.open_stream(native_name, filetype, mode)
            # apply the BASIC file wrapper
            return self._create_file_object(
                fhandle, filetype, mode, number, field, reclen, seg, offset, length
            )
        except Exception:
            self._locks.close_file(number)
            raise
def open ( self , number , filespec , filetype , mode , access , lock , reclen , seg , offset , length , field ) : # parse the file spec to a definite native name if not self . _native_root : # undefined disk drive: path not found raise error . BASICError ( error . PATH_NOT_FOUND ) # set default extension for programs if set ( filetype ) . intersection ( set ( b'MPBA' ) ) : defext = b'BAS' else : defext = b'' # translate the file name to something DOS-ish if necessary if mode == b'I' : native_name = self . _get_native_abspath ( filespec , defext , isdir = False , create = False ) else : # random files: try to open matching file # if it doesn't exist, use an all-caps 8.3 file name native_name = self . _get_native_abspath ( filespec , defext , isdir = False , create = True ) # handle locks, open stream and create file object # don't open output or append files more than once # whether it's the same file is determined by DOS basename, i.e. excluding directories! dos_basename = self . _get_dos_name_defext ( filespec , defext ) # obtain a lock self . _locks . open_file ( dos_basename , number , mode , lock , access ) try : # open the underlying stream fhandle = self . open_stream ( native_name , filetype , mode ) # apply the BASIC file wrapper return self . _create_file_object ( fhandle , filetype , mode , number , field , reclen , seg , offset , length ) except Exception : self . _locks . close_file ( number ) raise