admin_handler.py 文件源码

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

项目:territoriali-backend 作者: algorithm-ninja 项目源码 文件源码
def extract(self, filename:str, password:str):
        """
        POST /admin/extract
        """
        if os.path.exists(Config.contest_path):
            self.raise_exc(Forbidden, "CONTEST", "Contest already loaded")
        os.makedirs(Config.contest_path)
        wd = os.getcwd()
        z = os.path.abspath(os.path.join(Config.contest_zips, filename))
        os.chdir(Config.contest_path)
        try:
            with zipfile.ZipFile(z) as f:
                f.extractall(pwd=password.encode())
            Logger.info("CONTEST", "Contest extracted")
        except FileNotFoundError:
            BaseHandler.raise_exc(NotFound, "NOT_FOUND", "Archive %s not found" % z)
        except RuntimeError as ex:
            BaseHandler.raise_exc(Forbidden, "FAILED", str(ex))
        except PermissionError as ex:
            BaseHandler.raise_exc(Forbidden, "FAILED", str(ex))
        except zipfile.BadZipFile as ex:
            BaseHandler.raise_exc(Forbidden, "FAILED", str(ex))
        finally:
            os.chdir(wd)
        ContestManager.read_from_disk()
        return {}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号