Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
""" Content negotiation deals with selecting an appropriate renderer given the incoming request. Typically this will be based on the request's Accept header. """
raise NotImplementedError('.select_parser() must be implemented')
raise NotImplementedError('.select_renderer() must be implemented')
""" Given a list of parsers and a media type, return the appropriate parser to handle the incoming request. """ return None
""" Given a request and a list of renderers, return a two-tuple of: (renderer, media type). """ # Allow URL style format override. eg. "?format=json
# Check the acceptable media types against each renderer, # attempting more specific media types first # NB. The inner loop here isn't as bad as it first looks :) # Worst case is we're looping over len(accept_list) * len(self.renderers) # Return the most specific media type as accepted. _MediaType(media_type).precedence): # Eg client requests '*/*' # Accepted media type is 'application/json' else: # Eg client requests 'application/json; indent=8' # Accepted media type is 'application/json; indent=8'
""" If there is a '.json' style format suffix, filter the renderers so that we only negotiation against those that accept that format. """ if renderer.format == format] raise Http404
""" Given the incoming request, return a tokenised list of media type strings.
Allows URL style accept override. eg. "?accept=application/json" """ |