<s> '''<STR_LIT>''' <EOL> from __future__ import absolute_import <EOL> import tornado . websocket <EOL> from . import event_processor <EOL> from . saltnado import _check_cors_origin <EOL> import tornado . gen <EOL> import salt . utils <EOL> import salt . netapi <EOL> json = salt . utils . import_json ( ) <EOL> import logging <EOL> logger = logging . getLogger ( ) <EOL> class AllEventsHandler ( tornado . websocket . WebSocketHandler ) : <EOL> '''<STR_LIT>''' <EOL> def get ( self , token ) : <EOL> '''<STR_LIT>''' <EOL> logger . debug ( '<STR_LIT>' ) <EOL> self . token = token <EOL> if not self . application . auth . get_tok ( token ) : <EOL> logger . debug ( '<STR_LIT>' ) <EOL> self . send_error ( <NUM_LIT> ) <EOL> return <EOL> super ( AllEventsHandler , self ) . get ( token ) <EOL> def open ( self , token ) : <EOL> '''<STR_LIT>''' <EOL> self . connected = False <EOL> @ tornado . gen . coroutine <EOL> def on_message ( self , message ) : <EOL> """<STR_LIT>""" <EOL> logger . debug ( '<STR_LIT>' . format ( message ) ) <EOL> if message == '<STR_LIT>' : <EOL> if self . connected : <EOL> logger . debug ( '<STR_LIT>' ) <EOL> return <EOL> self . connected = True <EOL> while True : <EOL> try : <EOL> event = yield self . application . event_listener . get_event ( self ) <EOL> self . write_message ( u'<STR_LIT>' . format ( json . dumps ( event ) ) ) <EOL> except Exception as err : <EOL> logger . info ( '<STR_LIT>' . format ( str ( err ) ) ) <EOL> break <EOL> self . close ( ) <EOL> else : <EOL> pass <EOL> def on_close ( self , * args , ** kwargs ) : <EOL> '''<STR_LIT>''' <EOL> logger . debug ( '<STR_LIT>' ) <EOL> self . close ( ) <EOL> def check_origin ( self , origin ) : <EOL> """<STR_LIT>""" <EOL> mod_opts = self . application . mod_opts <EOL> if mod_opts . get ( '<STR_LIT>' ) : <EOL> return bool ( _check_cors_origin ( origin , mod_opts [ '<STR_LIT>' ] ) ) <EOL> else : <EOL> return super ( AllEventsHandler , self ) . check_origin ( origin ) <EOL> class FormattedEventsHandler ( AllEventsHandler ) : <EOL> @ tornado . gen . coroutine <EOL> def on_message ( self , message ) : <EOL> """<STR_LIT>""" <EOL> logger . debug ( '<STR_LIT>' . format ( message ) ) <EOL> if message == '<STR_LIT>' : <EOL> if self . connected : <EOL> logger . debug ( '<STR_LIT>' ) <EOL> return <EOL> self . connected = True <EOL> evt_processor = event_processor . SaltInfo ( self ) <EOL> client = salt . netapi . NetapiClient ( self . application . opts ) <EOL> client . run ( { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT:*>' , <EOL> '<STR_LIT>' : self . token , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> } ) <EOL> while True : <EOL> try : <EOL> event = yield self . application . event_listener . get_event ( self ) <EOL> evt_processor . process ( event , self . token , self . application . opts ) <EOL> except Exception as err : <EOL> logger . debug ( '<STR_LIT>' . format ( str ( err ) ) ) <EOL> break <EOL> self . close ( ) <EOL> else : <EOL> pass </s>
