예제 #1
0
 async def post(self, *, pid: int, file: lambda _: _):
     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)
     if file:
         data = file.file.read()
         try:
             data_dict = json.decode(data.decode('utf-8'))
         except Exception:
             self.json_or_redirect(self.url)
             return
         if pdoc['data']:
             await testdata.delete(self.domain_id, pdoc['data'])
         did = await testdata.add(self.domain_id, data_dict, self.user['_id'], testdata.TYPE_TEST_DATA,
                                  pid=pdoc['_id'])
         """
         md5 = hashlib.md5(data).hexdigest()
         fid = await fs.link_by_md5(md5)
         if not fid:
             fid = await fs.add_data(data)
         if pdoc.get('data'):
             await fs.unlink(pdoc['data'])
         """
         await problem.set_data(self.domain_id, pid, did)
     self.json_or_redirect(self.url)
예제 #2
0
 async def handler(msg, session):
     try:
         if msg.tp == sockjs.MSG_OPEN:
             await session.prepare()
             await session.on_open()
         elif msg.tp == sockjs.MSG_MESSAGE:
             await session.on_message(**json.decode(msg.data))
         elif msg.tp == sockjs.MSG_CLOSED:
             await session.on_close()
     except error.UserFacingError as e:
         _logger.warning('Websocket user facing error: %s', repr(e))
         session.close(4000, {'error': e.to_dict()})
예제 #3
0
async def get(token_id: str, token_type: int):
    """Get a token.
    Args:
        token_id: token ID.
        token_type: type of the token.

    Returns:
        The token document, or None.
    """
    db = await redis.database()
    doc = await db.get('token_' + token_id)
    if doc:
        return json.decode(doc.decode())
    else:
        return None
예제 #4
0
 async def on_notification(self, e):
     self.send(**json.decode(e['value']))
예제 #5
0
 async def on_message(self, e):
     self.send(**json.decode(e['value']))