On May 11, 5:37 pm, Graham Higgins <[email protected]> wrote:
> On Fri, 2012-05-11 at 02:18 -0700, Graham Klyne wrote:
> > I'm trying to use view_config accept parameters for HTTP content-type
> > negotiation, e.g.
>
> I can provide a partial answer ...

Graham,

Thanks for your clarifications.

They raise a couple of further questions...

> > (b) I can't see any way to create a catch-all match, to be used when
> > none of the view_config options *with* accept parameters are matched.
>
> The Pyramid URL dispatch mechanism is basically "An ordered set of
> patterns is checked one-by-one" so, if you simply remove the
> specialising match parameter, you're left with a catch-all which, to be
> effective, needs to appear last in the batting order:
>
> @view_config(route_name='service', request_method='GET')
> def service_default(request):
>     return Response("Default\n")

If using decorators to configure the views, how is "batting order"
defined.  It seems to me that it;'s somewhat at the whim of the Python
compiler?

> > (c) The matching doesn't honour the q= values generated by browsers;
> > e.g. I have Firefox generating:
>
> >   Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/
> > *;q=0.8,application/rdf+xml;q=0.93,text/rdf+n3;q=0.5
>
> > but I'm actually seeing the HTML version returned.
>
> > Is there something important I'm overlooking here?
>
> You just need to set the content-type of the response:
>
> @view_config(route_name='service', request_method='GET',
>              accept='text/turtle')
> def service_turtle(request):
>     return Response("TTL\n", content_type="text/turtle")

I'm doing that, but I don't see how it affects the selection of which
view to invoke.

(Maybe I wasn't clear:  when the different views are invoked, they
each return the appropriate content-type.  It's just that mis-spelled
or complex accept headers in the incoming request don't trigger the
desired view. I'm wondering if this should be raised as a bug against
Pyramid, because as it stands it seems one can't use this mechanism to
achieve effective content negotiation.)

Again, thanks for clarifying - I was thinking that maybe I was trying
to approach this goal from a completely wrong direction.

#g

-- 
You received this message because you are subscribed to the Google Groups 
"pylons-discuss" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/pylons-discuss?hl=en.

Reply via email to