<s> """<STR_LIT>""" <EOL> from gevent . pywsgi import WSGIServer <EOL> from geventwebsocket . handler import WebSocketHandler <EOL> import json <EOL> import argparse <EOL> from circus . consumer import CircusConsumer <EOL> from flask import Flask , request , render_template <EOL> ZMQ_ENDPOINT = '<STR_LIT>' <EOL> app = Flask ( __name__ ) <EOL> @ app . route ( '<STR_LIT:/>' ) <EOL> def index ( ) : <EOL> return render_template ( '<STR_LIT>' ) <EOL> @ app . route ( '<STR_LIT>' ) <EOL> def api ( ) : <EOL> """<STR_LIT>""" <EOL> ws = request . environ . get ( '<STR_LIT>' ) <EOL> topic = request . args . get ( '<STR_LIT>' ) <EOL> if None in ( ws , topic ) : <EOL> return <EOL> topic = topic . encode ( '<STR_LIT:ascii>' ) <EOL> for message , message_topic in CircusConsumer ( topic , endpoint = ZMQ_ENDPOINT ) : <EOL> response = json . dumps ( dict ( message = message , topic = message_topic ) ) <EOL> ws . send ( response ) <EOL> def main ( ) : <EOL> parser = argparse . ArgumentParser ( description = __doc__ ) <EOL> parser . add_argument ( '<STR_LIT>' , default = '<STR_LIT:127.0.0.1>' ) <EOL> parser . add_argument ( '<STR_LIT>' , default = <NUM_LIT> ) <EOL> args = parser . parse_args ( ) <EOL> server_loc = ( args . host , args . port ) <EOL> print ( '<STR_LIT>' % server_loc ) <EOL> http_server = WSGIServer ( server_loc , app , handler_class = WebSocketHandler ) <EOL> http_server . serve_forever ( ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> main ( ) </s>
