Skip to content
This repository was archived by the owner on Mar 6, 2025. It is now read-only.
This repository was archived by the owner on Mar 6, 2025. It is now read-only.

Pass event and context variables to after and on_exception decorators #7

@jonaswitt

Description

@jonaswitt

It doesn't cost anything and would enable a wider range of use cases. For example:

  1. To determine whether the response body may be gzip-encoded in an after callback, the event object needs to be inspected (to get the request header "Accept-Encoding")
  2. To pass state from the before to the after callback, the context variable could be used; e.g. to measure the time it took to process the request.

There's an initial proof-of-concept in jonaswitt@1ed4697 that works well for me.

For backwards compatibility, at least with the included decorators, it tries to figure out how many arguments the decorated function takes. I believe this could be extended to LambdaDecorator subclasses in order to avoid breaking existing user's code.
It uses getargspec() which works in Python 2 and 3 but is deprecated in Python 3. I haven't found a similar function that would work in both Python 2 and 3.

What do you think about this approach? I'd be happy to turn this into a PR (w/ updated documentation) if you agree with the general direction.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions