def best_match_content_type(self, action, supported_content_types=None, specific_content_types=None): """Determine the requested response content-type. Based on the query extension then the Accept header. Raise UnsupportedContentType exception if we don't find a preference """ supported_content_types = (supported_content_types or self.default_accept_types) parts = self.path.rsplit('.', 1) if len(parts) > 1: ctype = 'application/{0}'.format(parts[1]) if ctype in supported_content_types: return ctype if specific_content_types and action in specific_content_types: bm = self.accept.best_match(specific_content_types[action]) else: bm = self.accept.best_match(supported_content_types) if not bm: raise exceptions.UnsupportedContentType(content_type=self.accept) return bm
def get_content_type(self, allowed_content_types=None): """Determine content type of the request body. Does not do any body introspection, only checks header """ if "Content-Type" not in self.headers: return None content_type = self.content_type allowed_content_types = (allowed_content_types or self.default_request_content_types) if content_type not in allowed_content_types: raise exceptions.UnsupportedContentType(content_type=content_type) return content_type
def get_body_deserializer(self, content_type): try: return self.body_deserializers[content_type] except (KeyError, TypeError): raise exceptions.UnsupportedContentType(content_type=content_type)