Warning

This document is for an old release of Galaxy. You can alternatively view this page in the latest release if it exists or view the top of the latest release's documentation.

galaxy.web.framework.middleware package

WSGI Middleware.

Submodules

galaxy.web.framework.middleware.batch module

Batch API middleware

Adds a single route to the installation that:
  1. accepts a POST call containing a JSON array of ‘http-like’ JSON dictionaries.
  2. Each dictionary describes a single API call within the batch and is routed back by the middleware to the application’s handle_request as if it was a separate request.
  3. Each response generated is combined into a final JSON list that is returned from the POST call.

In this way, API calls can be kept properly atomic and the endpoint can compose them into complex tasks using only one request.

..note: This batch system is primarily designed for use by the UI as these types of batch operations reduce the number of requests for a given group of API tasks. IOW, this ain’t about batching jobs.

..warning: this endpoint is experimental is likely to change.

class galaxy.web.framework.middleware.batch.BatchMiddleware(application, galaxy, config=None)[source]

Bases: object

Adds a URL endpoint for processing batch API calls formatted as a JSON array of JSON dictionaries. These dictionaries are in the form: [

{
“url”: “/api/histories”, “type”: “POST”, “body”: “{ “name”: “New History Name” }”

]

where:
  • url is the url for the API call to be made including any query string
  • type is the HTTP method used (e.g. ‘POST’, ‘PUT’) - defaults to ‘GET’
  • body is the text body of the request (optional)
  • contentType content-type request header (defaults to application/json)
DEFAULT_CONFIG = {'route': '/api/batch', 'allowed_routes': ['^api\\/users.*', '^api\\/histories.*', '^api\\/jobs.*']}
__init__(application, galaxy, config=None)[source]
application = None

the wrapped webapp

galaxy = None

the original galaxy webapp

process_batch_requests(batch_environ, start_response)[source]

Loops through any provided JSON formatted ‘requests’, aggregates their JSON responses, and wraps them in the batch call response.

body_renderer(trans, body, environ, start_response)[source]
handle_exception(environ)[source]

galaxy.web.framework.middleware.error module

Error handler middleware

When an exception is thrown from the wrapper application, this logs the exception and displays an error page.

class galaxy.web.framework.middleware.error.ErrorMiddleware(application, global_conf=None, debug=<NoDefault>, error_email=None, error_log=None, show_exceptions_in_wsgi_errors=<NoDefault>, from_address=None, smtp_server=None, smtp_username=None, smtp_password=None, smtp_use_tls=False, error_subject_prefix=None, error_message=None, xmlhttp_key=None)[source]

Bases: object

Error handling middleware

Usage:

error_catching_wsgi_app = ErrorMiddleware(wsgi_app)

Settings:

debug:
If true, then tracebacks will be shown in the browser.
error_email:
an email address (or list of addresses) to send exception reports to
error_log:
a filename to append tracebacks to
show_exceptions_in_wsgi_errors:
If true, then errors will be printed to wsgi.errors (frequently a server error log, or stderr).
from_address, smtp_server, error_subject_prefix, smtp_username, smtp_password, smtp_use_tls:
variables to control the emailed exception reports
error_message:
When debug mode is off, the error message to show to users.
xmlhttp_key:
When this key (default _) is in the request GET variables (not POST!), expect that this is an XMLHttpRequest, and the response should be more minimal; it should not be a complete HTML page.

Environment Configuration:

paste.throw_errors:
If this setting in the request environment is true, then this middleware is disabled. This can be useful in a testing situation where you don’t want errors to be caught and transformed.
paste.expected_exceptions:
When this middleware encounters an exception listed in this environment variable and when the start_response has not yet occurred, the exception will be re-raised instead of being caught. This should generally be set by middleware that may (but probably shouldn’t be) installed above this middleware, and wants to get certain exceptions. Exceptions raised after start_response have been called are always caught since by definition they are no longer expected.
__init__(application, global_conf=None, debug=<NoDefault>, error_email=None, error_log=None, show_exceptions_in_wsgi_errors=<NoDefault>, from_address=None, smtp_server=None, smtp_username=None, smtp_password=None, smtp_use_tls=False, error_subject_prefix=None, error_message=None, xmlhttp_key=None)[source]
make_catching_iter(app_iter, environ, sr_checker)[source]
exception_handler(exc_info, environ)[source]
galaxy.web.framework.middleware.error.handle_exception(exc_info, error_stream, html=True, debug_mode=False, error_email=None, error_log=None, show_exceptions_in_wsgi_errors=False, error_email_from='errors@localhost', smtp_server='localhost', smtp_username=None, smtp_password=None, smtp_use_tls=False, error_subject_prefix='', error_message=None, simple_html_error=False, environ=None)[source]

For exception handling outside of a web context

Use like:

import sys
from paste.exceptions.errormiddleware import handle_exception
try:
    do stuff
except Exception:
    handle_exception(
        sys.exc_info(), sys.stderr, html=False, ...other config...)

If you want to report, but not fully catch the exception, call raise after handle_exception, which (when given no argument) will reraise the exception.

galaxy.web.framework.middleware.graphite module

Middleware for sending request statistics to graphite

class galaxy.web.framework.middleware.graphite.GraphiteMiddleware(application, graphite_host, graphite_port, graphite_prefix)[source]

Bases: object

This middleware will log request durations to the configured graphite instance.

__init__(application, graphite_host, graphite_port, graphite_prefix)[source]

galaxy.web.framework.middleware.profile module

Middleware that profiles the request with cProfile and displays profiling information at the bottom of each page.

class galaxy.web.framework.middleware.profile.ProfileMiddleware(app, global_conf=None, limit=40)[source]

Bases: object

Middleware that profiles all requests.

All HTML pages will have profiling information appended to them. The data is isolated to that single request, and does not include data from previous requests.

__init__(app, global_conf=None, limit=40)[source]
galaxy.web.framework.middleware.profile.pstats_as_html(stats, *sel_list)[source]

Return an HTML representation of a pstats.Stats object.

galaxy.web.framework.middleware.profile.get_func_list(stats, sel_list)[source]

Use ‘sel_list’ to select a list of functions to display.

galaxy.web.framework.middleware.profile.func_std_string(func_name)[source]

Match what old profile produced

galaxy.web.framework.middleware.remoteuser module

Middleware for handling $REMOTE_USER if use_remote_user is enabled.

class galaxy.web.framework.middleware.remoteuser.RemoteUser(app, maildomain=None, display_servers=None, admin_users=None, single_user=None, remote_user_header=None, remote_user_secret_header=None, normalize_remote_user_email=False)[source]

Bases: object

__init__(app, maildomain=None, display_servers=None, admin_users=None, single_user=None, remote_user_header=None, remote_user_secret_header=None, normalize_remote_user_email=False)[source]
error(start_response, title='Access denied', message='Please contact your local Galaxy administrator.')[source]

galaxy.web.framework.middleware.request_id module

class galaxy.web.framework.middleware.request_id.RequestIDMiddleware(app, global_conf=None)[source]

Bases: object

A WSGI middleware that creates a unique ID for the request and puts it in the environment

__init__(app, global_conf=None)[source]

galaxy.web.framework.middleware.sentry module

raven.middleware

copyright:
  1. 2010-2012 by the Sentry Team, see AUTHORS for more details.
license:

BSD, see LICENSE for more details.

class galaxy.web.framework.middleware.sentry.Sentry(application, dsn)[source]

Bases: object

A WSGI middleware which will attempt to capture any uncaught exceptions and send them to Sentry.

__init__(application, dsn)[source]
handle_exception(environ)[source]

galaxy.web.framework.middleware.static module

class galaxy.web.framework.middleware.static.CacheableStaticURLParser(directory, cache_seconds=None)[source]

Bases: paste.urlparser.StaticURLParser

__init__(directory, cache_seconds=None)[source]
galaxy.web.framework.middleware.static.make_static(global_conf, document_root, cache_seconds=None)[source]

galaxy.web.framework.middleware.statsd module

Middleware for sending request statistics to statsd

class galaxy.web.framework.middleware.statsd.StatsdMiddleware(application, statsd_host, statsd_port, statsd_prefix)[source]

Bases: object

This middleware will log request durations to the configured statsd instance.

__init__(application, statsd_host, statsd_port, statsd_prefix)[source]

galaxy.web.framework.middleware.translogger module

Middleware for logging requests, using Apache combined log format

class galaxy.web.framework.middleware.translogger.TransLogger(application, logger=None, format=None, logging_level=20, logger_name='wsgi', setup_console_handler=True, set_logger_level=10)[source]

Bases: object

This logging middleware will log all requests as they go through. They are, by default, sent to a logger named 'wsgi' at the INFO level.

If setup_console_handler is true, then messages for the named logger will be sent to the console.

__init__(application, logger=None, format=None, logging_level=20, logger_name='wsgi', setup_console_handler=True, set_logger_level=10)[source]
format = '%(REMOTE_ADDR)s - %(REMOTE_USER)s [%(time)s] "%(REQUEST_METHOD)s %(REQUEST_URI)s %(HTTP_VERSION)s" %(status)s %(bytes)s "%(HTTP_REFERER)s" "%(HTTP_USER_AGENT)s"'
write_log(environ, method, req_uri, start, status, bytes)[source]
galaxy.web.framework.middleware.translogger.make_filter(app, global_conf, logger_name='wsgi', format=None, logging_level=20, setup_console_handler=True, set_logger_level=10)[source]

This logging middleware will log all requests as they go through. They are, by default, sent to a logger named 'wsgi' at the INFO level.

If setup_console_handler is true, then messages for the named logger will be sent to the console.

galaxy.web.framework.middleware.xforwardedhost module

class galaxy.web.framework.middleware.xforwardedhost.XForwardedHostMiddleware(app, global_conf=None)[source]

Bases: object

A WSGI middleware that changes the HTTP host header in the WSGI environ based on the X-Forwarded-Host header IF found

__init__(app, global_conf=None)[source]