def make_middleware(app): if tg_version_tuple < (2, 1): app = base_config.add_tosca2_middleware(app) app = FCommConnectorMiddleware(app) app = make_moksha_middleware(app, tg.config) return app
def make_app(global_conf, full_stack=True, **app_conf): """ Set tg2 up with the settings found in the PasteDeploy configuration file used. :param global_conf: The global settings for tg2 (those defined under the ``[DEFAULT]`` section). :type global_conf: dict :param full_stack: Should the whole TG2 stack be set up? :type full_stack: str or bool :return: The tg2 application with all the relevant middleware loaded. This is the PasteDeploy factory for the tg2 application. ``app_conf`` contains all the application-specific settings (those defined under ``[app:main]``. """ wrap_app = lambda app: make_moksha_middleware( make_middleware(app), app_conf, ) app = make_base_app(global_conf, full_stack=True, wrap_app=wrap_app, **app_conf) return app
def make_app(global_conf, full_stack=True, **app_conf): """ Set busmon up with the settings found in the PasteDeploy configuration file used. :param global_conf: The global settings for busmon (those defined under the ``[DEFAULT]`` section). :type global_conf: dict :param full_stack: Should the whole TG2 stack be set up? :type full_stack: str or bool :return: The busmon application with all the relevant middleware loaded. This is the PasteDeploy factory for the busmon application. ``app_conf`` contains all the application-specific settings (those defined under ``[app:main]``. """ if tg.__version__ < '2.1.0': # Oh... epel. :( wrap_app = lambda app: make_tw2_middleware( make_moksha_middleware( app, app_conf, ), default_engine='mako', res_prefix=tg.config.get( 'busmon.resource_path_prefix', '/busmon/resources/', ), ) else: # On modern TG, tw2 is included. wrap_app = lambda app: make_moksha_middleware(app, app_conf) app = make_base_app(global_conf, full_stack=True, wrap_app=wrap_app, **app_conf) # Wrap your base TurboGears 2 application with custom middleware here return app
def make_app(global_conf, full_stack=True, **app_conf): """ Set busmon up with the settings found in the PasteDeploy configuration file used. :param global_conf: The global settings for busmon (those defined under the ``[DEFAULT]`` section). :type global_conf: dict :param full_stack: Should the whole TG2 stack be set up? :type full_stack: str or bool :return: The busmon application with all the relevant middleware loaded. This is the PasteDeploy factory for the busmon application. ``app_conf`` contains all the application-specific settings (those defined under ``[app:main]``. """ if tg.__version__ < '2.1.0': # Oh... epel. :( wrap_app = lambda app: make_tw2_middleware( make_moksha_middleware( app, app_conf, ), default_engine='mako', res_prefix=tg.config.get( 'busmon.resource_path_prefix', '/busmon/resources/', ), ) else: # On modern TG, tw2 is included. wrap_app = lambda app: make_moksha_middleware(app, app_conf) app = make_base_app( global_conf, full_stack=True, wrap_app=wrap_app, **app_conf) # Wrap your base TurboGears 2 application with custom middleware here return app
def kernel(config): def app(environ, start_response): start_response('200 OK', [('Content-Type', 'text/html')]) socket = get_moksha_socket(config) return map(str, [socket.display()]) app = make_moksha_middleware(app, config) app = make_tw2_middleware(app, config) app = webtest.TestApp(app) self.app = app
def kernel(config): def app(environ, start_response): start_response('200 OK', [('Content-Type', 'text/html')]) class MyWidget(moksha.wsgi.widgets.api.live.LiveWidget): template = "moksha.wsgi.tests.templates.empty" onmessage = 'console.log(json)' topic = 'test' backend = config['moksha.livesocket.backend'] return map(str, [MyWidget.display()]) app = make_moksha_middleware(app, config) app = make_tw2_middleware(app, config) app = webtest.TestApp(app) self.app = app
template = "" @app.route("/") def hello(): config = get_moksha_appconfig() socket = moksha.wsgi.widgets.api.get_moksha_socket(config) return flask.templating.render_template_string( simple_template, notification_widget=PopupNotification, moksha_socket=socket, ) class HelloWorldProducer(moksha.hub.api.producer.PollingProducer): frequency = datetime.timedelta(seconds=2) def poll(self): self.send_message('hello_world', "Hello World!") if __name__ == "__main__": # Load development.ini config = get_moksha_appconfig() # Wrap the inner wsgi app with our middlewares app.wsgi_app = make_moksha_middleware(app.wsgi_app, config) app.wsgi_app = make_middleware(app.wsgi_app) app.run(debug=True)