async def handler(request): try: await request.post() except ValueError: return web.HTTPOk() return web.HTTPBadRequest()
def handler(request): request.match_info.add_app(app) return web.HTTPOk(text='OK')
def handler(request): return web.HTTPOk(text='OK')
async def get_root(_request): raise web.HTTPOk()
async def receive_hook(self, request): topic = request.match_info["topic"] payload = await request.json() self.hook_results.append((topic, payload)) raise web.HTTPOk()
def handler(request): return web.HTTPOk(text='Test message')
async def handler(request: web.Request) -> web.Response: nonlocal called called = True raise web.HTTPOk()
async def index(request): is_anon = await is_anonymous(request) if is_anon: return web.HTTPUnauthorized() return web.HTTPOk()
async def index_read(request): return web.HTTPOk()
async def receive_message(self, request): payload = await request.json() self.headers = request.headers self.message_results.append(payload) raise web.HTTPOk()
async def http200(request): raise web.HTTPOk(body=b'')
def handler(request): ws = web.WebSocketResponse() if not ws.can_prepare(request): return web.HTTPUpgradeRequired() return web.HTTPOk()
}) def test_repr(): with pytest.raises(TypeError): Jsonify(default_repr=False).dumps({ 'x': object, }) Jsonify(default_repr=True).dumps({ 'x': object, }) @pytest.mark.parametrize('data', [ '', b'', web.HTTPOk(), ]) async def test_binary(test_client, data): async def h(request): return data def factory(loop, *args, **kwargs): app = web.Application(loop=loop, middlewares=[middlewares.binary]) app.router.add_get('/', h) return app cli = await test_client(factory) resp = await cli.get('/') assert resp.status == 200, await resp.text()
async def render_conf(self, request): file_name = request.rel_url.parts[-1] url_root = '{scheme}://{host}'.format(scheme=request.scheme, host=request.host) headers = dict([('CONTENT-DISPOSITION', 'attachment; filename="%s"' % file_name)]) rendered = await self.api_logic.render_config(url_root=url_root) return web.HTTPOk(body=rendered, headers=headers)
def handler(request): data = yield from request.post() assert b'data' == data['unknown'].file.read() assert data['unknown'].content_type == 'application/octet-stream' assert data['unknown'].filename == 'unknown' return web.HTTPOk()
async def index_write(request): return web.HTTPOk()
def handler(request): data = yield from request.post() assert data == {'some': 'data'} return web.HTTPOk()
async def index_forbid(request): return web.HTTPOk()
def test_default_body(): resp = web.HTTPOk() assert b'200: OK' == resp.body
def process(self): return web.HTTPOk()
async def handler(request: web.Request) -> web.Response: raise web.HTTPOk()
async def callback(r : web.Request): try: request_json = await r.json() hash = request_json['hash'] log.server_logger.debug(f"callback received {hash}") request_json['block'] = json.loads(request_json['block']) link = request_json['block']['link_as_account'] if r.app['subscriptions'].get(link): log.server_logger.info("Pushing to clients %s", str(r.app['subscriptions'][link])) for sub in r.app['subscriptions'][link]: if sub in r.app['clients']: await r.app['clients'][sub].send_str(json.dumps(request_json)) # If natrium account and send, send to web page for donations if 'is_send' in request_json and (request_json['is_send'] or request_json['is_send'] == 'true') and link == 'nano_1natrium1o3z5519ifou7xii8crpxpk8y65qmkih8e8bpsjri651oza8imdd': log.server_logger.info('Detected send to natrium account') if 'amount' in request_json: log.server_logger.info(f'emitting donation event for amount: {request_json["amount"]}') await sio.emit('donation_event', {'amount':request_json['amount']}) # Push FCM notification if this is a send if fcm_api_key is None: return web.HTTPOk() fcm_tokens = set(await get_fcm_tokens(link, r)) fcm_tokens_v2 = set(await get_fcm_tokens(link, r, v2=True)) if (fcm_tokens is None or len(fcm_tokens) == 0) and (fcm_tokens_v2 is None or len(fcm_tokens_v2) == 0): return web.HTTPOk() message = { "action":"block", "hash":request_json['block']['previous'] } response = await rpc.json_post(message) if response is None: return web.HTTPOk() # See if this block was already pocketed cached_hash = await r.app['rdata'].get(f"link_{hash}") if cached_hash is not None: return web.HTTPOk() prev_data = response prev_data = prev_data['contents'] = json.loads(prev_data['contents']) prev_balance = int(prev_data['contents']['balance']) cur_balance = int(request_json['block']['balance']) send_amount = prev_balance - cur_balance if send_amount >= 1000000000000000000000000: # This is a send, push notifications fcm = aiofcm.FCM(fcm_sender_id, fcm_api_key) # Send notification with generic title, send amount as body. App should have localizations and use this information at its discretion for t in fcm_tokens: message = aiofcm.Message( device_token=t, data = { "amount": str(send_amount) }, priority=aiofcm.PRIORITY_HIGH ) await fcm.send_message(message) notification_title = f"Received {util.raw_to_nano(send_amount)} {'NANO' if not banano_mode else 'BANANO'}" notification_body = f"Open {'Natrium' if not banano_mode else 'Kalium'} to view this transaction." for t2 in fcm_tokens_v2: message = aiofcm.Message( device_token = t2, notification = { "title":notification_title, "body":notification_body, "sound":"default", "tag":link }, data = { "click_action": "FLUTTER_NOTIFICATION_CLICK", "account": link }, priority=aiofcm.PRIORITY_HIGH ) await fcm.send_message(message) return web.HTTPOk() except Exception: log.server_logger.exception("received exception in callback") return web.HTTPInternalServerError(reason=f"Something went wrong {str(sys.exc_info())}")
async def get_other(_request): raise web.HTTPOk()
async def healthCheck(request): """Return 200 to say the application is healthy. """ return web.HTTPOk()
async def handler(request): return web.HTTPOk()
async def logout(request): response = web.HTTPOk() await forget(request, response) return response
def handler(request): assert request.app is subapp return web.HTTPOk(text='OK')
def handler(request): data = yield from request.read() with fname.open('rb') as f: content = f.read() assert content == data return web.HTTPOk()
async def ping(request): return web.HTTPOk()
async def handler_with_ok_permission(self, request): return web.HTTPOk()