<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def save(self, event):
 """Saves a file that is specified in event.attr Parameters event.attr: Dict \tkey filepath contains file path of file to be saved """


        filepath = event.attr["filepath"]

        try:
            filetype = event.attr["filetype"]
        except KeyError:
            filetype = "pys"

        # If saving is already in progress abort
        if self.saving:
            return

        # Use tmpfile to make sure that old save file does not get lost
        # on abort save

        __, tmpfilepath = tempfile.mkstemp()

        if filetype == "xls":
            self._set_save_states()
            self._save_xls(tmpfilepath)
            self._move_tmp_file(tmpfilepath, filepath)
            self._release_save_states()

        elif filetype == "pys" or filetype == "all":
            self._set_save_states()
            if self._save_pys(tmpfilepath):
                # Writing was successful
                self._move_tmp_file(tmpfilepath, filepath)
                self._save_sign(filepath)
            self._release_save_states()

        elif filetype == "pysu":
            self._set_save_states()
            if self._save_pysu(tmpfilepath):
                # Writing was successful
                self._move_tmp_file(tmpfilepath, filepath)
                self._save_sign(filepath)
            self._release_save_states()

        else:
            os.remove(tmpfilepath)
            msg = "Filetype {filetype} unknown.".format(filetype=filetype)
            raise ValueError(msg)

        try:
            os.remove(tmpfilepath)
        except OSError:
            pass