Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add request.current_service attribute #105

Closed
almet opened this issue Jan 25, 2013 · 2 comments
Closed

Add request.current_service attribute #105

almet opened this issue Jan 25, 2013 · 2 comments
Labels

Comments

@almet
Copy link
Contributor

almet commented Jan 25, 2013

In #98, @rfk said:

As a larger architectural thought, I wonder if we should pass the service object into each validator by default. IOW, make the signature of a validator function "validate(service, request)" or similar. How common is it to make a validator that closes over the service object like this?

@almet
Copy link
Contributor Author

almet commented Jan 25, 2013

That is something I did a lot for this CORS work, and probably it could be useful in other cases. I'm also thinking about making the service available in the view as well (maybe in request.service). What do you think?

@leplatrem leplatrem mentioned this issue Aug 24, 2016
6 tasks
@leplatrem leplatrem changed the title Pass the service object into each validator by default Add request.current_service attribute Oct 20, 2016
@leplatrem
Copy link
Contributor

def current_service(request):
    """Return the Cornice service matching the specified request.

    :returns: the service or None if unmatched.
    :rtype: cornice.Service
    """
    if request.matched_route:
        services = request.registry.cornice_services
        pattern = request.matched_route.pattern
        try:
            service = services[pattern]
        except KeyError:
            return None
        else:
            return service

config.add_request_method(current_service, reify=True)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants