# Path: sockjs/cyclone/proto.py
# CONNECT = 'o'
# DISCONNECT = 'c'
# MESSAGE = 'm'
# HEARTBEAT = 'h'
# def disconnect(code, reason):
# 
# Path: sockjs/cyclone/transports/pollingbase.py
# class PollingTransportBase(basehandler.PreflightHandler, base.BaseTransportMixin):
#     def initialize(self, server):
#     def _get_session(self, session_id):
#     def _attach_session(self, session_id, start_heartbeat=True):
#     def _detach(self):
#     def check_xsrf_cookie(self):
#     def send_message(self, message, stats=True):
#     def session_closed(self):
#     def on_connection_close(self, reason):


from twisted.python import log
from cyclone.web import asynchronous
from sockjs.cyclone import proto
from sockjs.cyclone.transports import pollingbase
    def send_pack(self, message):
        self.set_header('Content-Type', 'application/javascript; charset=UTF-8')
        self.set_header('Content-Length', len(message) + 1)
        self.write(message + '\n')

        self._detach()

        self.safe_finish()


class XhrSendHandler(pollingbase.PollingTransportBase):
    def post(self, session_id):
        self.preflight()
        self.handle_session_cookie()
        self.disable_cache()

        session = self._get_session(session_id)

        if session is None:
            self.set_status(404)
            return

        #data = self.request.body.decode('utf-8')
        data = self.request.body
        if not data:
            self.write("Payload expected.")
            self.set_status(500)
            return

        try:

# Path: sockjs/cyclone/proto.py
# CONNECT = 'o'
# DISCONNECT = 'c'
# MESSAGE = 'm'
# HEARTBEAT = 'h'
# def disconnect(code, reason):
# 
# Path: sockjs/cyclone/transports/pollingbase.py
# class PollingTransportBase(basehandler.PreflightHandler, base.BaseTransportMixin):
#     def initialize(self, server):
#     def _get_session(self, session_id):
#     def _attach_session(self, session_id, start_heartbeat=True):
#     def _detach(self):
#     def check_xsrf_cookie(self):
#     def send_message(self, message, stats=True):
#     def session_closed(self):
#     def on_connection_close(self, reason):


# Path: sockjs/cyclone/transports/xhr.py
from twisted.python import log
from cyclone.web import asynchronous
from sockjs.cyclone import proto
from sockjs.cyclone.transports import pollingbase

    def send_pack(self, message):
        self.set_header('Content-Type', 'application/javascript; charset=UTF-8')
        self.set_header('Content-Length', len(message) + 1)
        self.write(message + '\n')

        self._detach()

        self.safe_finish()


class XhrSendHandler(pollingbase.PollingTransportBase):
    def post(self, session_id):
        self.preflight()
        self.handle_session_cookie()
        self.disable_cache()

        session = self._get_session(session_id)

        if session is None:
            self.set_status(404)
            return

        #data = self.request.body.decode('utf-8')
        data = self.request.body
        if not data:
            self.write("Payload expected.")
            self.set_status(500)
            return

        try:

            messages = proto.json_decode(data)