=====================
Bottle-Werkzeug
=====================

`Werkzeug <http://werkzeug.pocoo.org/>`_ is a powerful WSGI utility library for 
Python. It includes an interactive debugger and feature-packed request and response 
objects.

This plugin integrates :class:`werkzeug.wrappers.Request` and
:class:`werkzeug.wrappers.Response` as an alternative to the built-in
implementations, adds support for :mod:`werkzeug.exceptions` and replaces the
default error page with an interactive debugger.



Installation
===============

Install with one of the following commands::

    $ pip install bottle-werkzeug
    $ easy_install bottle-werkzeug

or download the latest version from github::

    $ git clone git://github.com/defnull/bottle.git
    $ cd bottle/plugins/werkzeug
    $ python setup.py install



Usage
===============

Once installed to an application, this plugin adds support for 
:class:`werkzeug.wrappers.Response`, all kinds of :mod:`werkzeug.exceptions` and
provides a thread-local instance of :class:`werkzeug.wrappers.Request` that is
updated with each request. The plugin instance itself doubles as a werkzeug
module object, so you don't have to import werkzeug in your application. Here
is an example::

    import bottle

    app = bottle.Bottle()
    werkzeug = bottle.ext.werkzeug.Plugin()
    app.install(werkzeug)

    req = werkzueg.request # For the lazy.

    @app.route('/hello/:name')
    def say_hello(name):
        greet = {'en':'Hello', 'de':'Hallo', 'fr':'Bonjour'}
        language = req.accept_languages.best_match(greet.keys())
        if language:
            return werkzeug.Response('%s %s!' % (greet[language], name))
        else:
            raise werkzeug.exceptions.NotAcceptable()



Using the Debugger
====================

This plugin replaces the default error page with an advanced debugger. If you
have the `evalex` feature enabled, you will get an interactive console that
allows you to inspect the error context in the browser. Please read
`Debugging Applications with werkzeug <werkzeug:debug>`_ before you enable this
feature.



Configuration
=============

The following configuration options exist for the plugin class:

* **evalex**: Enable the exception evaluation feature (interactive debugging). This requires a non-forking server and is a security risk. Please read `Debugging Applications with werkzeug <werkzeug:debug>`_. (default: False)
* **request_class**: Defaults to :class:`werkzeug.wrappers.Request`
* **debugger_class**: Defaults to a subclass of :class:`werkzeug.debug.DebuggedApplication` which obeys the :data:`bottle.DEBUG` setting.

