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 {}
admin_handler.py 文件源码
python
阅读 25
收藏 0
点赞 0
评论 0
评论列表
文章目录