Beispiel #1
0
 def __init__(self, media_type_str):
     if media_type_str is None:
         media_type_str = ''
     self.orig = media_type_str
     self.full_type, self.params = parse_header(
         media_type_str.encode(HTTP_HEADER_ENCODING))
     self.main_type, sep, self.sub_type = self.full_type.partition('/')
Beispiel #2
0
    def get_indent(self, accepted_media_type, renderer_context):
        if accepted_media_type:
            # If the media type looks like 'application/json; indent=4',
            # then pretty print the result.
            base_media_type, params = parse_header(accepted_media_type.encode('ascii'))
            try:
                return max(min(int(params['indent']), 8), 0)
            except (KeyError, ValueError, TypeError):
                pass

        # If 'indent' is provided in the context, then pretty print the result.
        # E.g. If we're being called by the BrowsableAPIRenderer.
        return renderer_context.get('indent', None)
Beispiel #3
0
    def get_version(self, request):
        version = None

        # Attempt to get version from Accept header
        accepts = request.headers.get("Accept")
        if accepts:
            _, params = parse_header(accepts)
            version = params.get('v')

        # Attempt to get version from query params
        if not version:
            try:
                version = request.arguments['v'][0]
            except (KeyError, TypeError, IndexError):
                pass

        return version
Beispiel #4
0
 def __init__(self, media_type_str):
     if media_type_str is None:
         media_type_str = ''
     self.orig = media_type_str
     self.full_type, self.params = parse_header(media_type_str.encode(HTTP_HEADER_ENCODING))
     self.main_type, sep, self.sub_type = self.full_type.partition('/')