handlers.py 文件源码

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

项目:jupyter-notebook-gist 作者: mozilla 项目源码 文件源码
def post(self):
        # url and filename are sent in a JSON encoded blob
        post_data = tornado.escape.json_decode(self.request.body)

        nb_url = post_data['nb_url']
        nb_name = base64.b64decode(post_data['nb_name']).decode('utf-8')
        force_download = post_data['force_download']

        file_path = os.path.join(os.getcwd(), nb_name)

        if os.path.isfile(file_path):
            if not force_download:
                raise HTTPError(409, "ERROR: File already exists.")

        response = request_session.get(nb_url, stream=True)
        with open(file_path, 'wb') as fd:
            # TODO: check if this is a good chunk size
            for chunk in response.iter_content(1024):
                fd.write(chunk)

        self.write(nb_name)
        self.flush()
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号