async def get(self, *, rid: objectid.ObjectId): rdoc = await record.get(rid) if not rdoc: raise error.RecordNotFoundError(rid) ddoc = await document.get(rdoc['domain_id'], document.TYPE_PRETEST_DATA, rdoc['data_id']) if not ddoc: raise error.ProblemDataNotFoundError(rdoc['pid']) output_buffer = io.BytesIO() zip_file = zipfile.ZipFile(output_buffer, 'a', zipfile.ZIP_DEFLATED) config_content = str(len(ddoc['data_input'])) + "\n" for i, (data_input, data_output) in enumerate( zip(ddoc['data_input'], ddoc['data_output'])): input_file = 'input{0}.txt'.format(i) output_file = 'output{0}.txt'.format(i) config_content += '{0}|{1}|1|10|1024\n'.format( input_file, output_file) zip_file.writestr('Input/{0}'.format(input_file), data_input) zip_file.writestr('Output/{0}'.format(output_file), data_output) zip_file.writestr('Config.ini', config_content) # mark all files as created in Windows for zfile in zip_file.filelist: zfile.create_system = 0 zip_file.close() await self.binary(output_buffer.getvalue())
async def get(self, *, pid: document.convert_doc_id): # Judges will have PRIV_READ_PROBLEM_DATA, # domain administrators will have PERM_READ_PROBLEM_DATA, # problem owner will have PERM_READ_PROBLEM_DATA_SELF. pdoc = await problem.get(self.domain_id, pid) if (not self.own(pdoc, builtin.PERM_READ_PROBLEM_DATA_SELF) and not self.has_perm(builtin.PERM_READ_PROBLEM_DATA)): self.check_priv(builtin.PRIV_READ_PROBLEM_DATA) fdoc = await problem.get_data(self.domain_id, pid) if not fdoc: raise error.ProblemDataNotFoundError(self.domain_id, pid) self.redirect(options.cdn_prefix.rstrip('/') + \ self.reverse_url('fs_get', domain_id=builtin.DOMAIN_ID_SYSTEM, secret=fdoc['metadata']['secret']))
async def get_data(domain_id, pid): pdoc = await get(domain_id, pid) if not pdoc.get('data', None): raise error.ProblemDataNotFoundError(domain_id, pid) return await fs.get_meta(pdoc['data'])
async def get_data_md5(domain_id: str, pid: document.convert_doc_id): pdoc = await get(domain_id, pid) if not pdoc['data']: raise error.ProblemDataNotFoundError(domain_id, pid) return await fs.get_md5(pdoc['data'])