# Path: sockjs/exceptions.py
# class SessionIsAcquired(SockjsException):
#     """Session is acquired."""
# 
# class SessionIsClosed(SockjsException):
#     """Session is closed."""
# 
# Path: sockjs/protocol.py
# def close_frame(code, reason):
#     return FRAME_CLOSE + json.dumps([code, reason], **kwargs)
# 
# ENCODING = "utf-8"
# 
# Path: sockjs/protocol.py
# STATE_CLOSING = 2
# 
# STATE_CLOSED = 3
# 
# FRAME_CLOSE = "c"
# 
# FRAME_MESSAGE = "a"


import aiohttp
import asyncio
from ..exceptions import SessionIsAcquired, SessionIsClosed
from ..protocol import close_frame, ENCODING
from ..protocol import STATE_CLOSING, STATE_CLOSED, FRAME_CLOSE, FRAME_MESSAGE

    timeout = None
    maxsize = 131072  # 128K bytes

    def __init__(self, manager, session, request):
        super().__init__(manager, session, request)

        self.size = 0
        self.response = None

    async def send(self, text):
        blob = (text + "\n").encode(ENCODING)
        await self.response.write(blob)

        self.size += len(blob)
        if self.size > self.maxsize:
            return True
        else:
            return False

    async def handle_session(self):
        assert self.response is not None, "Response is not specified."

        # session was interrupted
        if self.session.interrupted:
            await self.send(close_frame(1002, "Connection interrupted"))

        # session is closing or closed
        elif self.session.state in (STATE_CLOSING, STATE_CLOSED):
            await self.session._remote_closed()

# Path: sockjs/exceptions.py
# class SessionIsAcquired(SockjsException):
#     """Session is acquired."""
# 
# class SessionIsClosed(SockjsException):
#     """Session is closed."""
# 
# Path: sockjs/protocol.py
# def close_frame(code, reason):
#     return FRAME_CLOSE + json.dumps([code, reason], **kwargs)
# 
# ENCODING = "utf-8"
# 
# Path: sockjs/protocol.py
# STATE_CLOSING = 2
# 
# STATE_CLOSED = 3
# 
# FRAME_CLOSE = "c"
# 
# FRAME_MESSAGE = "a"


# Path: sockjs/transports/base.py
import aiohttp
import asyncio
from ..exceptions import SessionIsAcquired, SessionIsClosed
from ..protocol import close_frame, ENCODING
from ..protocol import STATE_CLOSING, STATE_CLOSED, FRAME_CLOSE, FRAME_MESSAGE


    timeout = None
    maxsize = 131072  # 128K bytes

    def __init__(self, manager, session, request):
        super().__init__(manager, session, request)

        self.size = 0
        self.response = None

    async def send(self, text):
        blob = (text + "\n").encode(ENCODING)
        await self.response.write(blob)

        self.size += len(blob)
        if self.size > self.maxsize:
            return True
        else:
            return False

    async def handle_session(self):
        assert self.response is not None, "Response is not specified."

        # session was interrupted
        if self.session.interrupted:
            await self.send(close_frame(1002, "Connection interrupted"))

        # session is closing or closed
        elif self.session.state in (STATE_CLOSING, STATE_CLOSED):
            await self.session._remote_closed()

            await self.send(close_frame(3000, "Go away!"))