# 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/ws.py
# def WSSuccess(payload=None, detail=None):
#     payload = payload or {}
#     payload['status'] = WS_STATUS.SUCCESS
# 
#     if detail:
#         payload['detail'] = str(detail)
# 
#     return json.dumps(payload)
# 
# def WSFailure(payload=None, detail=None):
#     payload = payload or {}
#     payload.update({
#         'status': WS_STATUS.FAILURE,
#         'detail': str(detail or "Request execution error."),
#     })
#     return json.dumps(payload)
# 
# 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/streaming/subscribers/base.py
# class StreamingSubscriber(metaclass=abc.ABCMeta):
# 
#     @abc.abstractmethod
#     async def write(self, o: Any) -> Awaitable[None]:
#         pass


import logging
from enum import IntEnum
from typing import Any, Awaitable
from aiohttp import web, WSMsgType
from il2fb.ds.airbridge import json
from il2fb.ds.airbridge.api.http.responses.ws import WSSuccess, WSFailure
from il2fb.ds.airbridge.api.http.security import with_authorization
from il2fb.ds.airbridge.streaming.subscribers.base import StreamingSubscriber

    async def _unsubscribe_from_chat(self) -> Awaitable[None]:
        await self._chat_stream.unsubscribe(self)
        self._subscriptions.remove(self._chat_stream)

    async def _subscribe_to_events(self, **kwargs) -> Awaitable[None]:
        await self._events_stream.subscribe(self, **kwargs)
        self._subscriptions.append(self._events_stream)

    async def _unsubscribe_from_events(self) -> Awaitable[None]:
        await self._events_stream.unsubscribe(self)
        self._subscriptions.remove(self._events_stream)

    async def _subscribe_to_not_parsed_strings(self, **kwargs) -> Awaitable[None]:
        await self._not_parsed_strings_stream.subscribe(self, **kwargs)
        self._subscriptions.append(self._not_parsed_strings_stream)

    async def _unsubscribe_from_not_parsed_strings(self) -> Awaitable[None]:
        await self._not_parsed_strings_stream.unsubscribe(self)
        self._subscriptions.remove(self._not_parsed_strings_stream)

    async def _subscribe_to_radar(self, **kwargs) -> Awaitable[None]:
        await self._radar_stream.subscribe(self, **kwargs)
        self._subscriptions.append(self._radar_stream)

    async def _unsubscribe_from_radar(self) -> Awaitable[None]:
        await self._radar_stream.unsubscribe(self)
        self._subscriptions.remove(self._radar_stream)

    async def write(self, o: Any) -> Awaitable[None]:

# 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/ws.py
# def WSSuccess(payload=None, detail=None):
#     payload = payload or {}
#     payload['status'] = WS_STATUS.SUCCESS
# 
#     if detail:
#         payload['detail'] = str(detail)
# 
#     return json.dumps(payload)
# 
# def WSFailure(payload=None, detail=None):
#     payload = payload or {}
#     payload.update({
#         'status': WS_STATUS.FAILURE,
#         'detail': str(detail or "Request execution error."),
#     })
#     return json.dumps(payload)
# 
# 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/streaming/subscribers/base.py
# class StreamingSubscriber(metaclass=abc.ABCMeta):
# 
#     @abc.abstractmethod
#     async def write(self, o: Any) -> Awaitable[None]:
#         pass


# Path: il2fb/ds/airbridge/api/http/views/streaming.py
import logging
from enum import IntEnum
from typing import Any, Awaitable
from aiohttp import web, WSMsgType
from il2fb.ds.airbridge import json
from il2fb.ds.airbridge.api.http.responses.ws import WSSuccess, WSFailure
from il2fb.ds.airbridge.api.http.security import with_authorization
from il2fb.ds.airbridge.streaming.subscribers.base import StreamingSubscriber


    async def _unsubscribe_from_chat(self) -> Awaitable[None]:
        await self._chat_stream.unsubscribe(self)
        self._subscriptions.remove(self._chat_stream)

    async def _subscribe_to_events(self, **kwargs) -> Awaitable[None]:
        await self._events_stream.subscribe(self, **kwargs)
        self._subscriptions.append(self._events_stream)

    async def _unsubscribe_from_events(self) -> Awaitable[None]:
        await self._events_stream.unsubscribe(self)
        self._subscriptions.remove(self._events_stream)

    async def _subscribe_to_not_parsed_strings(self, **kwargs) -> Awaitable[None]:
        await self._not_parsed_strings_stream.subscribe(self, **kwargs)
        self._subscriptions.append(self._not_parsed_strings_stream)

    async def _unsubscribe_from_not_parsed_strings(self) -> Awaitable[None]:
        await self._not_parsed_strings_stream.unsubscribe(self)
        self._subscriptions.remove(self._not_parsed_strings_stream)

    async def _subscribe_to_radar(self, **kwargs) -> Awaitable[None]:
        await self._radar_stream.subscribe(self, **kwargs)
        self._subscriptions.append(self._radar_stream)

    async def _unsubscribe_from_radar(self) -> Awaitable[None]:
        await self._radar_stream.unsubscribe(self)
        self._subscriptions.remove(self._radar_stream)

    async def write(self, o: Any) -> Awaitable[None]:

        await self._ws.send_str(json.dumps(o))