<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_hash(self, location, basedir, ext=None):
 """ Save response body into file with special path builded from hash. That allows to lower number of files per directory. :param location: URL of file or something else. It is used to build the SHA1 hash. :param basedir: base directory to save the file. Note that file will not be saved directly to this directory but to some sub-directory of `basedir` :param ext: extension which should be appended to file name. The dot is inserted automatically between filename and extension. :returns: path to saved file relative to `basedir` Example:: 'e8/dc/f2918108788296df1facadc975d32b361a6a.png' TODO: replace `basedir` with two options: root and save_to. And returns save_to + path """


        if isinstance(location, six.text_type):
            location = location.encode('utf-8')
        rel_path = hashed_path(location, ext=ext)
        path = os.path.join(basedir, rel_path)
        if not os.path.exists(path):
            path_dir, _ = os.path.split(path)
            try:
                os.makedirs(path_dir)
            except OSError:
                pass
            with open(path, 'wb') as out:
                out.write(self._bytes_body)
        return rel_path