コード例 #1
0
 async def handler(request):
     try:
         await request.post()
     except ValueError:
         return web.HTTPOk()
     return web.HTTPBadRequest()
コード例 #2
0
 def handler(request):
     request.match_info.add_app(app)
     return web.HTTPOk(text='OK')
コード例 #3
0
 def handler(request):
     return web.HTTPOk(text='OK')
コード例 #4
0
 async def get_root(_request):
     raise web.HTTPOk()
コード例 #5
0
 async def receive_hook(self, request):
     topic = request.match_info["topic"]
     payload = await request.json()
     self.hook_results.append((topic, payload))
     raise web.HTTPOk()
コード例 #6
0
 def handler(request):
     return web.HTTPOk(text='Test message')
コード例 #7
0
 async def handler(request: web.Request) -> web.Response:
     nonlocal called
     called = True
     raise web.HTTPOk()
コード例 #8
0
 async def index(request):
     is_anon = await is_anonymous(request)
     if is_anon:
         return web.HTTPUnauthorized()
     return web.HTTPOk()
コード例 #9
0
 async def index_read(request):
     return web.HTTPOk()
コード例 #10
0
 async def receive_message(self, request):
     payload = await request.json()
     self.headers = request.headers
     self.message_results.append(payload)
     raise web.HTTPOk()
コード例 #11
0
async def http200(request):
    raise web.HTTPOk(body=b'')
コード例 #12
0
    def handler(request):
        ws = web.WebSocketResponse()
        if not ws.can_prepare(request):
            return web.HTTPUpgradeRequired()

        return web.HTTPOk()
コード例 #13
0
    })


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()
コード例 #14
0
 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)
コード例 #15
0
 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()
コード例 #16
0
 async def index_write(request):
     return web.HTTPOk()
コード例 #17
0
 def handler(request):
     data = yield from request.post()
     assert data == {'some': 'data'}
     return web.HTTPOk()
コード例 #18
0
 async def index_forbid(request):
     return web.HTTPOk()
コード例 #19
0
def test_default_body():
    resp = web.HTTPOk()
    assert b'200: OK' == resp.body
コード例 #20
0
ファイル: test_route.py プロジェクト: timson/sockjs
 def process(self):
     return web.HTTPOk()
コード例 #21
0
 async def handler(request: web.Request) -> web.Response:
     raise web.HTTPOk()
コード例 #22
0
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())}")
コード例 #23
0
 async def get_other(_request):
     raise web.HTTPOk()
コード例 #24
0
async def healthCheck(request):
    """Return 200 to say the application is healthy.

    
    """
    return web.HTTPOk()
コード例 #25
0
 async def handler(request):
     return web.HTTPOk()
コード例 #26
0
async def logout(request):
    response = web.HTTPOk()
    await forget(request, response)
    return response
コード例 #27
0
 def handler(request):
     assert request.app is subapp
     return web.HTTPOk(text='OK')
コード例 #28
0
 def handler(request):
     data = yield from request.read()
     with fname.open('rb') as f:
         content = f.read()
     assert content == data
     return web.HTTPOk()
コード例 #29
0
async def ping(request):
    return web.HTTPOk()
コード例 #30
0
ファイル: test_permissions.py プロジェクト: dennypenta/aiommy
 async def handler_with_ok_permission(self, request):
     return web.HTTPOk()