handlers.py 文件源码

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

项目:nbpuller 作者: data-8 项目源码 文件源码
def open(self, username, args):
        util.logger.info('({}) Websocket connected'.format(username))

        # We don't do validation since we assume that the LandingHandler did
        # it. TODO: ENHANCE SECURITY
        is_file_request = ('file_url' in args)

        try:
            if is_file_request:
                message = yield thread_pool.submit(
                    download_file_and_redirect,
                    username=username,
                    file_url=args['file_url'],
                    config=options.config,
                )
            else:
                if 'branch' not in args:
                    args['branch'] = Config.DEFAULT_BRANCH_NAME
                if 'notebook_path' not in args:
                    args['notebook_path'] = ''
                if 'domain' not in args:
                    args['domain'] = Config.DEFAULT_DOMAIN
                if 'account' not in args:
                    args['account'] = Config.DEFAULT_GITHUB_ACCOUNT

                message = yield thread_pool.submit(
                    pull_from_remote,
                    username=username,
                    repo_name=args['repo'],
                    domain=args['domain'],
                    account=args['account'],
                    branch_name=args['branch'],
                    paths=args['path'],
                    config=options.config,
                    notebook_path=args['notebook_path'],
                    progress=Progress(username, self.write_message)
                )

            if message['type'] == "ERROR":
                util.logger.exception('Sent message: {}'.format(message))
            else:
                util.logger.info('Sent message: {}'.format(message))
            self.write_message(message)
        except Exception as e:
            # If something bad happens, the client should see it
            message = messages.error(str(e))
            util.logger.exception('Sent message: {}'.format(message))
            self.write_message(message)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号