WSGI Application

The code in here is basically a vanilla

webapp2.WSGIApplication class with additional error handling capabilites. See Error Handling Guide for a reference.

Also Route is included for your convenience.

For example in app.yaml add:

handlers:
    - url: /
      script: home.app

home.py should look like this:

from gaetk2.handlers import DefaultHandler
from gaetk2.application import WSGIApplication, Route

class HomeHandler(DefaultHandler):
    def get(self):
        self.return_text('it worked')

app = WSGIApplication([Route('/', handler=HomeHandler)])

gaetk2.application package

class gaetk2.application.WSGIApplication(routes=None, debug=False, config=None)[source]

Overwrite exception handling.

For further information see the paret class at http://webapp2.readthedocs.io/en/latest/api/webapp2.html#webapp2.WSGIApplication

handle_exception(request, response, e)[source]

Handles a uncaught exception occurred in __call__().

Uncaught exceptions can be handled by error handlers registered in error_handlers. This is a dictionary that maps HTTP status codes to callables that will handle the corresponding error code. If the exception is not an HTTPException, the status code 500 is used.

The error handlers receive (request, response, exception) and can be a callable or a string in dotted notation to be lazily imported.

If no error handler is found, the exception is re-raised.

Parameters:
  • request – A Request instance.
  • response – A Response instance.
  • e – The uncaught exception.
Returns:

The returned value from the error handler.

default_exception_handler(request, response, exception)[source]

Exception aufbereiten und loggen.

get_sentry_addon(request)[source]

Try to extract additional data from the request for Sentry after an Exception tootk place.

Parameters:request – The Request Object
Returns:a dict to be sent to sentry as addon.
classify_exception(request, exception)[source]

Based on the exception raised we classify it for logging.

We not only return an HTTP Status code and level, but also a fingerprint and dict of tags to help snetry group the errors.

setup_logging(request, response)[source]

Provide sentry early on with information from the context.

Called at the beginning of each request. Some information is already set in sentry.py during initialisation.

fix_unicode_headers(response)[source]

Ensure all Headers are Unicode.

class gaetk2.application.Route(template, handler=None, name=None, defaults=None, build_only=False, handler_method=None, methods=None, schemes=None)[source]

A route definition that maps a URI path to a handler.

The initial concept was based on `Another Do-It-Yourself Framework`_, by Ian Bicking.

defaults = None

Default parameters values.

methods = None

Sequence of allowed HTTP methods. If not set, all methods are allowed.

schemes = None

Sequence of allowed URI schemes. If not set, all schemes are allowed.

regex[source]

Lazy route template parser.

match(request)[source]

Matches this route against the current request.

Raises:exc.HTTPMethodNotAllowed if the route defines methods and the request method isn’t allowed.

See also

BaseRoute.match().

build(request, args, kwargs)[source]

Returns a URI for this route.

See also

Router.build().