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

Accept predicate with wildcard not allowed #1407

Closed
ltvolks opened this issue Sep 5, 2014 · 6 comments
Closed

Accept predicate with wildcard not allowed #1407

ltvolks opened this issue Sep 5, 2014 · 6 comments
Milestone

Comments

@ltvolks
Copy link

ltvolks commented Sep 5, 2014

The docs for the accept predicate state that wildcards are allowed, but due to the way the 'offer' is checked in WebOb, an accept predicate with any wildcard component will fail:

ValueError: The application should offer specific types, got 'text/*'

Here's a simple example:

from wsgiref.simple_server import make_server
from pyramid.config import Configurator
from pyramid.response import Response


def index(request):
    return Response("Index")

if __name__ == '__main__':
    config = Configurator()
    config.add_route('index', path='/')
    config.add_view(index, route_name='index', accept='text/*')
    app = config.make_wsgi_app()
    server = make_server('0.0.0.0', 8080, app)
    server.serve_forever()
Traceback (most recent call last):
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/wsgiref/handlers.py", line 85, in run
    self.result = application(self.environ, self.start_response)
  File "/pyenv/test-accept/lib/python2.7/site-packages/pyramid/router.py", line 242, in __call__
    response = self.invoke_subrequest(request, use_tweens=True)
  File "/pyenv/test-accept/lib/python2.7/site-packages/pyramid/router.py", line 217, in invoke_subrequest
    response = handle_request(request)
  File "/pyenv/test-accept/lib/python2.7/site-packages/pyramid/tweens.py", line 46, in excview_tween
    response = view_callable(exc, request)
  File "/pyenv/test-accept/lib/python2.7/site-packages/pyramid/config/views.py", line 329, in attr_view
    return view(context, request)
  File "/pyenv/test-accept/lib/python2.7/site-packages/pyramid/config/views.py", line 300, in predicate_wrapper
    if not predicate(context, request):
  File "/pyenv/test-accept/lib/python2.7/site-packages/pyramid/config/predicates.py", line 136, in __call__
    return self.val in request.accept
  File "/pyenv/test-accept/lib/python2.7/site-packages/webob/acceptparse.py", line 120, in __contains__
    if self._match(mask, offer):
  File "/pyenv/test-accept/lib/python2.7/site-packages/webob/acceptparse.py", line 303, in _match
    _check_offer(offer)
  File "/pyenv/test-accept/lib/python2.7/site-packages/webob/acceptparse.py", line 320, in _check_offer
    raise ValueError("The application should offer specific types, got %r" % offer)
ValueError: The application should offer specific types, got 'text/*'
@digitalresistor
Copy link
Member

Could you file a bug against WebOb please?

https://github.com/Pylons/webob/

@tisdall
Copy link
Contributor

tisdall commented Sep 5, 2014

There seems to be a lack of documentation for WebOb that it even does this, but the source code indicates that it should work.

@marioidival
Copy link

This issue was opened in WebOb repository, here can be closed?

@ltvolks
Copy link
Author

ltvolks commented Sep 11, 2014

I think it makes sense to leave it open until/if WebOb incorporates a solution and Pyramid is able to depend on that. If WebOb doesn't change, then this is still at least a documentation issue for Pyramid.

@digitalresistor
Copy link
Member

This has now been fixed in WebOb using the patch provided by @ltvolks.

@digitalresistor digitalresistor added this to the 1.7 milestone Jan 29, 2016
@mmerickel
Copy link
Member

Looks like this will be in webob 1.6.

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

No branches or pull requests

5 participants