storage.py 文件源码

python
阅读 16 收藏 0 点赞 0 评论 0

项目:django-cockatiel 作者: raphaelm 项目源码 文件源码
def _save(self, name, content):
        if not hasattr(content, 'seek'):
            raise SuspiciousFileOperation('The django-cockatiel backend can only deal with '
                                          'files that support seeking.')
        content.seek(0)
        sha1 = hashlib.sha1()
        while True:
            chunk = content.read(1024)
            if not chunk:
                break
            sha1.update(chunk)

        content.seek(0)

        def put(node):
            resp = requests.put(self._get_url(node, name), data=content, headers={
                'X-Content-SHA1': sha1.hexdigest()
            }, allow_redirects=False)
            resp.raise_for_status()
            return resp

        resp = self._retry(put)
        loc = resp.headers['Location']
        if loc.startswith('/'):
            loc = loc[1:]
        return loc
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号