

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

dataset/ETHPy150Open lorien/grab/grab/document.py Document.save_hash/original