2018-04-17 12:18:40 +00:00
|
|
|
"""OpenAPI core responses models module"""
|
2018-05-30 13:46:54 +00:00
|
|
|
from openapi_core.schema.content.exceptions import MimeTypeNotFound
|
|
|
|
from openapi_core.schema.content.models import Content
|
2018-04-18 10:39:03 +00:00
|
|
|
from openapi_core.schema.media_types.exceptions import InvalidContentType
|
2018-04-17 12:18:40 +00:00
|
|
|
|
|
|
|
|
|
|
|
class Response(object):
|
|
|
|
|
|
|
|
def __init__(
|
|
|
|
self, http_status, description, headers=None, content=None,
|
|
|
|
links=None):
|
|
|
|
self.http_status = http_status
|
|
|
|
self.description = description
|
|
|
|
self.headers = headers and dict(headers) or {}
|
2018-05-30 13:46:54 +00:00
|
|
|
self.content = content and Content(content) or Content()
|
2018-04-17 12:18:40 +00:00
|
|
|
self.links = links and dict(links) or {}
|
|
|
|
|
|
|
|
def __getitem__(self, mimetype):
|
2018-08-17 14:54:01 +00:00
|
|
|
return self.get_content_type(mimetype)
|
|
|
|
|
|
|
|
def get_content_type(self, mimetype):
|
2018-04-17 12:18:40 +00:00
|
|
|
try:
|
|
|
|
return self.content[mimetype]
|
2018-05-30 13:46:54 +00:00
|
|
|
except MimeTypeNotFound:
|
2018-09-06 14:50:16 +00:00
|
|
|
raise InvalidContentType(mimetype)
|