# 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.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
# coding: utf-8




LOG = logging.getLogger(__name__)


@with_authorization
async def get_all_ships_positions(request):
    pretty = 'pretty' in request.query
    timeout = request.query.get('timeout')

    try:
        if timeout is not None:
            timeout = float(timeout)
    except Exception:
        LOG.exception(
            "HTTP failed to get all ships positions: incorrect input data"
        )
        return RESTBadRequest(
            detail="incorrect input data",
            pretty=pretty,
        )

    try:
        result = await request.app['radar'].get_all_ships_positions(timeout)
    except Exception:
        LOG.exception("HTTP failed to get all ships positions")

# 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/radar.py
import logging
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

# coding: utf-8




LOG = logging.getLogger(__name__)


@with_authorization
async def get_all_ships_positions(request):
    pretty = 'pretty' in request.query
    timeout = request.query.get('timeout')

    try:
        if timeout is not None:
            timeout = float(timeout)
    except Exception:
        LOG.exception(
            "HTTP failed to get all ships positions: incorrect input data"
        )
        return RESTBadRequest(
            detail="incorrect input data",
            pretty=pretty,
        )

    try:
        result = await request.app['radar'].get_all_ships_positions(timeout)
    except Exception:
        LOG.exception("HTTP failed to get all ships positions")

        return RESTInternalServerError(