<commit_before>Moksha Middleware
=================

Moksha can run as an application serving platform on its own, but
also contains a small piece of WSGI middleware that provides your 
application with a lot of additional functionality as well.  This allows you to use Moksha in your existing `WSGI <http://www.python.org/dev/peps/pep-0333/>`_ application.

It currently provides the following functionality

    * Sets up the feed storage and cache for widgets
    * Handles dispatching moksha applications, which can be any WSGI app
    * Handles dispatching to individual widgets, which are simply `ToscaWidgets <http://toscawidgets.org>`_
    * Sets up `SQLAlchemy` database engines for each application
    * Initializes applications data models
    * Loads all application configuration

Using the MokshaMiddleware
--------------------------

Using the MokshaMiddleware with an existing WSGI application is quite
simple.  It will look a bit different with each framework, but here is
how it looks in TurboGears2.  If you're using Moksha as a stand-alone platform, this is automatically setup for you.

.. code-block:: python

    """TurboGears middleware initialization"""
    from myapp.config.app_cfg import base_config
    from myapp.config.environment import load_environment

    # make_base_app will wrap the TG2 app with all the middleware it needs. 
    make_base_app = base_config.setup_tg_wsgi_app(load_environment)

    def make_app(global_conf, full_stack=True, **app_conf):
        from moksha.middlware import MokshaMiddleware<commit_msg>Bring our Middleware docs up to date a bit<commit_after>=================
Moksha Middleware
=================

Moksha can run as an application serving platform on its own, but
also contains a small piece of WSGI middleware that provides your 
application with a lot of additional functionality as well.  This allows you to use Moksha in your existing `WSGI <http://www.python.org/dev/peps/pep-0333/>`_ application.

It currently provides the following functionality

    * Sets up the feed storage and cache for widgets
    * Handles dispatching moksha applications, which can be any WSGI app
    * Handles dispatching to individual widgets, which are simply `ToscaWidgets <http://toscawidgets.org>`_
    * Sets up `SQLAlchemy` database engines for each application
    * Initializes applications data models
    * Loads all application configuration
    * Sets up the moksha resource connectors
    * Sets up the stomp callback registry

Using the MokshaMiddleware
--------------------------

Using the MokshaMiddleware with an existing WSGI application is quite
simple.  It will look a bit different with each framework, but here is
how it looks in TurboGears2.  If you're using Moksha as a stand-alone platform, this is automatically setup for you.

.. code-block:: python

    """TurboGears middleware initialization"""
    from myapp.config.app_cfg import base_config
    from myapp.config.environment import load_environment

    # make_base_app will wrap the TG2 app with all the middleware it needs. 
    make_base_app = base_config.setup_tg_wsgi_app(load_environment)

    def make_app(global_conf, full_stack=True, **app_conf):
        from moksha.middlware import MokshaMiddleware
{'fraction_non_alphanumeric': 0.07846153846153846, 'fraction_numerical': 0.0036923076923076922, 'mean_word_length': 3.970948012232416, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7426739', 'n_tokens_mistral': 887, 'n_tokens_neox': 856, 'n_words': 374}