# 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):


import urllib
from cyclone.web import asynchronous
from twisted.python import log
from sockjs.cyclone import proto
from sockjs.cyclone.transports import pollingbase
        self.handle_session_cookie()                                            
        self.disable_cache()                                                    
                                                                                
        # Grab callback parameter                                               
        self.callback = self.get_argument('c', None)                            
        if not self.callback:                                                   
            self.write('"callback" parameter required')                         
            self.set_status(500)                                                
            self.finish()                                                       
            return                                                              

        # Get or create session without starting heartbeat
        if not self._attach_session(session_id):
            return

        # Might get already detached because connection was closed in
        # connectionMade
        if not self.session:
            return

        if self.session.send_queue.is_empty():
            self.session.start_heartbeat()
        else:
            self.session.flush()

    def connectionLost(self, reason):
        self.session.delayed_close()

    def send_pack(self, message):
        # TODO: Just escape

# 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/jsonp.py
import urllib
from cyclone.web import asynchronous
from twisted.python import log
from sockjs.cyclone import proto
from sockjs.cyclone.transports import pollingbase

        self.handle_session_cookie()                                            
        self.disable_cache()                                                    
                                                                                
        # Grab callback parameter                                               
        self.callback = self.get_argument('c', None)                            
        if not self.callback:                                                   
            self.write('"callback" parameter required')                         
            self.set_status(500)                                                
            self.finish()                                                       
            return                                                              

        # Get or create session without starting heartbeat
        if not self._attach_session(session_id):
            return

        # Might get already detached because connection was closed in
        # connectionMade
        if not self.session:
            return

        if self.session.send_queue.is_empty():
            self.session.start_heartbeat()
        else:
            self.session.flush()

    def connectionLost(self, reason):
        self.session.delayed_close()

    def send_pack(self, message):
        # TODO: Just escape

        msg = '%s(%s);\r\n' % (self.callback, proto.json_encode(message))