# Path: il2fb/ds/airbridge/json.py
# class JSONEncoder(_json.JSONEncoder):
#     def default(self, obj):
# def object_decoder(obj):
# 
# Path: il2fb/ds/airbridge/api/http/responses/rest.py
# class RESTBadRequest(RESTResponse):
#     status = 400
#     detail = "Bad request"
# 
# Path: il2fb/ds/airbridge/api/http/responses/rest.py
# class RESTInternalServerError(RESTResponse):
#     status = 500
#     detail = (
#         "The server encountered an unexpected condition that prevented it "
#         "from fulfilling the request"
#     )
# 
# Path: il2fb/ds/airbridge/api/http/responses/rest.py
# class RESTSuccess(RESTResponse):
#     status = 200
# 
# Path: il2fb/ds/airbridge/api/http/security.py
# def with_authorization(view):
# 
#     @functools.wraps(view)
#     async def wrapper(arg0, *args, **kwargs):
#         request = arg0 if isinstance(arg0, web.Request) else arg0.request
#         backend = request.app.get('auth_backend')
# 
#         if backend and not backend.authorize(request):
#             raise web.HTTPForbidden()
# 
#         return (await view(arg0, *args, **kwargs))
# 
#     return wrapper


import logging
from il2fb.commons.organization import Belligerents
from il2fb.ds.airbridge import json
from il2fb.ds.airbridge.api.http.responses.rest import RESTBadRequest
from il2fb.ds.airbridge.api.http.responses.rest import RESTInternalServerError
from il2fb.ds.airbridge.api.http.responses.rest import RESTSuccess
from il2fb.ds.airbridge.api.http.security import with_authorization
            timeout = float(timeout)

        addressee = request.match_info['addressee']
        addressee = int(addressee)
        addressee = Belligerents.get_by_value(addressee)

        body = await request.json(loads=json.loads)
        message = body['message']
    except Exception:
        LOG.exception(
            "HTTP failed to chat to belligerent: incorrect input data"
        )
        return RESTBadRequest(
            detail="incorrect input data",
            pretty=pretty,
        )

    try:
        await request.app['console_client'].chat_to_belligerent(
            message=message,
            addressee=addressee,
            timeout=timeout,
        )
    except Exception:
        LOG.exception("HTTP failed to chat to belligerent")
        return RESTInternalServerError(
            detail="failed to chat to belligerent",
            pretty=pretty,
        )
    else:

# Path: il2fb/ds/airbridge/json.py
# class JSONEncoder(_json.JSONEncoder):
#     def default(self, obj):
# def object_decoder(obj):
# 
# Path: il2fb/ds/airbridge/api/http/responses/rest.py
# class RESTBadRequest(RESTResponse):
#     status = 400
#     detail = "Bad request"
# 
# Path: il2fb/ds/airbridge/api/http/responses/rest.py
# class RESTInternalServerError(RESTResponse):
#     status = 500
#     detail = (
#         "The server encountered an unexpected condition that prevented it "
#         "from fulfilling the request"
#     )
# 
# Path: il2fb/ds/airbridge/api/http/responses/rest.py
# class RESTSuccess(RESTResponse):
#     status = 200
# 
# Path: il2fb/ds/airbridge/api/http/security.py
# def with_authorization(view):
# 
#     @functools.wraps(view)
#     async def wrapper(arg0, *args, **kwargs):
#         request = arg0 if isinstance(arg0, web.Request) else arg0.request
#         backend = request.app.get('auth_backend')
# 
#         if backend and not backend.authorize(request):
#             raise web.HTTPForbidden()
# 
#         return (await view(arg0, *args, **kwargs))
# 
#     return wrapper


# Path: il2fb/ds/airbridge/api/http/views/chat.py
import logging
from il2fb.commons.organization import Belligerents
from il2fb.ds.airbridge import json
from il2fb.ds.airbridge.api.http.responses.rest import RESTBadRequest
from il2fb.ds.airbridge.api.http.responses.rest import RESTInternalServerError
from il2fb.ds.airbridge.api.http.responses.rest import RESTSuccess
from il2fb.ds.airbridge.api.http.security import with_authorization

            timeout = float(timeout)

        addressee = request.match_info['addressee']
        addressee = int(addressee)
        addressee = Belligerents.get_by_value(addressee)

        body = await request.json(loads=json.loads)
        message = body['message']
    except Exception:
        LOG.exception(
            "HTTP failed to chat to belligerent: incorrect input data"
        )
        return RESTBadRequest(
            detail="incorrect input data",
            pretty=pretty,
        )

    try:
        await request.app['console_client'].chat_to_belligerent(
            message=message,
            addressee=addressee,
            timeout=timeout,
        )
    except Exception:
        LOG.exception("HTTP failed to chat to belligerent")
        return RESTInternalServerError(
            detail="failed to chat to belligerent",
            pretty=pretty,
        )
    else:

        return RESTSuccess(pretty=pretty)