<s> from twisted . python import log <EOL> from sockjs . cyclone import proto <EOL> from sockjs . cyclone . transports import base <EOL> from sockjs . cyclone import websocket <EOL> class WebSocketTransport ( websocket . WebSocketHandler , base . BaseTransportMixin ) : <EOL> """<STR_LIT>""" <EOL> name = '<STR_LIT>' <EOL> def initialize ( self , server ) : <EOL> self . server = server <EOL> self . session = None <EOL> def connectionMade ( self , session_id ) : <EOL> self . server . stats . connectionOpened ( ) <EOL> if self . server . settings [ '<STR_LIT>' ] : <EOL> self . transport . setTcpNoDelay ( True ) <EOL> self . session = self . server . create_session ( session_id , register = False ) <EOL> if not self . session . set_handler ( self ) : <EOL> self . transport . loseConnection ( ) <EOL> return <EOL> self . session . verify_state ( ) <EOL> if self . session : <EOL> self . session . flush ( ) <EOL> def _detach ( self ) : <EOL> if self . session is not None : <EOL> self . session . remove_handler ( self ) <EOL> self . session = None <EOL> def messageReceived ( self , message ) : <EOL> if not message or not self . session : <EOL> return <EOL> try : <EOL> msg = proto . json_decode ( message ) <EOL> if isinstance ( msg , list ) : <EOL> self . session . messagesReceived ( msg ) <EOL> else : <EOL> self . session . messagesReceived ( ( msg , ) ) <EOL> except Exception as e : <EOL> log . msg ( '<STR_LIT>' % e ) <EOL> self . transport . loseConnection ( ) <EOL> def connectionLost ( self , reason ) : <EOL> if self . session is not None : <EOL> self . server . stats . connectionClosed ( ) <EOL> session = self . session <EOL> self . _detach ( ) <EOL> session . close ( ) <EOL> def send_pack ( self , message ) : <EOL> self . sendMessage ( message ) <EOL> def session_closed ( self ) : <EOL> self . transport . loseConnection ( ) <EOL> self . _detach ( ) <EOL> def auto_decode ( self ) : <EOL> return False </s>
