<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def open(self, filepath, mode='w+b'):
 """Opens a file - will actually return a temporary file but replace the original file when the context is closed. """

        #Check if the filepath can be accessed and is writable before creating
        #the tempfile
        if not _isFileAccessible(filepath):
            raise IOError('File %s is not writable' % (filepath,))

        if filepath in self._files:
            with open(self._files[filepath], mode=mode) as tmpf:
                yield tmpf
        else:
            tempfilepath = None
            with tempfile.NamedTemporaryFile(delete=False, mode=mode) as tmpf:
                tempfilepath = tmpf.name
                yield tmpf
            self._files[filepath] = tempfilepath