(self, name, number, mode, lock_type, access)
Register a disk file and try to acquire a file lock.
Register a disk file and try to acquire a file lock.
Register a disk file and try to acquire a file lock .
def open_file(self, name, number, mode, lock_type, access):
        """Register a disk file and try to acquire a file lock."""
        already_open = self.list_open(name)
        if mode in (b'O', b'A') and already_open:
            raise error.BASICError(error.FILE_ALREADY_OPEN)
        if not number:
            return
        for f in already_open:
            if (
                    # default mode: don't accept if SHARED/LOCK present
                    ((not lock_type) and f.lock_type) or
                    # LOCK READ WRITE: don't accept if already open
                    (lock_type == b'RW') or
                    # defined locking: don't accept if open in default mode
                    (lock_type and not f.lock_type) or
                    # LOCK READ or LOCK WRITE: accept based on ACCESS of open file
                    (
                        lock_type and lock_type != b'SHARED' and
                        f.access and set(iterchar(lock_type)) & set(iterchar(f.access))
                    ) or
                    (
                        f.lock_type and f.lock_type != b'SHARED' and
                        (
                            (access and set(iterchar(f.lock_type)) & set(iterchar(access))) or
                            # can't open with unspecified access if other is LOCK READ WRITE
                            (not access and set(iterchar(f.lock_type)) == {b'R', b'W'})
                        )
                    )
                ):
                raise error.BASICError(error.PERMISSION_DENIED)
        # setting this only after the lock acquisition makes the check asymmetric
        # which is what GW-BASIC does...
        # first file to open with unspecified access gets RW access
        # but second file gets checked for ''
        if lock_type and not access:
            access = b'RW'
        self._locking_parameters[number] = LockingParameters(name, mode, lock_type, access)
def open_file ( self , name , number , mode , lock_type , access ) : already_open = self . list_open ( name ) if mode in ( b'O' , b'A' ) and already_open : raise error . BASICError ( error . FILE_ALREADY_OPEN ) if not number : return for f in already_open : if ( # default mode: don't accept if SHARED/LOCK present ( ( not lock_type ) and f . lock_type ) or # LOCK READ WRITE: don't accept if already open ( lock_type == b'RW' ) or # defined locking: don't accept if open in default mode ( lock_type and not f . lock_type ) or # LOCK READ or LOCK WRITE: accept based on ACCESS of open file ( lock_type and lock_type != b'SHARED' and f . access and set ( iterchar ( lock_type ) ) & set ( iterchar ( f . access ) ) ) or ( f . lock_type and f . lock_type != b'SHARED' and ( ( access and set ( iterchar ( f . lock_type ) ) & set ( iterchar ( access ) ) ) or # can't open with unspecified access if other is LOCK READ WRITE ( not access and set ( iterchar ( f . lock_type ) ) == { b'R' , b'W' } ) ) ) ) : raise error . BASICError ( error . PERMISSION_DENIED ) # setting this only after the lock acquisition makes the check asymmetric # which is what GW-BASIC does... # first file to open with unspecified access gets RW access # but second file gets checked for '' if lock_type and not access : access = b'RW' self . _locking_parameters [ number ] = LockingParameters ( name , mode , lock_type , access )