<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def saveWallet(self, wallet, fpath):
 """Save wallet into specified localtion. Returns the canonical path for the ``fpath`` where ``wallet`` has been stored. Error cases: - ``fpath`` is not inside the keyrings base dir - ValueError raised - directory part of ``fpath`` exists and it's not a directory - NotADirectoryError raised - ``fpath`` exists and it's a directory - IsADirectoryError raised :param wallet: wallet to save :param fpath: wallet file path, absolute or relative to keyrings base dir """

        if not fpath:
            raise ValueError("empty path")

        _fpath = self._normalize(fpath)
        _dpath = _fpath.parent

        try:
            _dpath.relative_to(self._baseDir)
        except ValueError:
            raise ValueError(
                "path {} is not is not relative to the keyrings {}".format(
                    fpath, self._baseDir))

        self._createDirIfNotExists(_dpath)

        # ensure permissions from the bottom of the directory hierarchy
        while _dpath != self._baseDir:
            self._ensurePermissions(_dpath, self.dmode)
            _dpath = _dpath.parent

        with _fpath.open("w") as wf:
            self._ensurePermissions(_fpath, self.fmode)
            encodedWallet = self.encode(wallet)
            wf.write(encodedWallet)
            logger.debug("stored wallet '{}' in {}".format(
                wallet.name, _fpath))

        return str(_fpath)