mirror of
https://github.com/correl/openapi-core.git
synced 2024-11-29 03:00:12 +00:00
6bdd1a6756
Main motivation behind this change is to be able to catch exceptions as per raise_for_errors() helpers, but to inspect state of exceptions instead of just getting a rendered string. This allows rendering exceptions into JSON, for example.
21 lines
505 B
Python
21 lines
505 B
Python
"""OpenAPI core content models module"""
|
|
import fnmatch
|
|
|
|
from six import iteritems
|
|
|
|
from openapi_core.schema.content.exceptions import MimeTypeNotFound
|
|
|
|
|
|
class Content(dict):
|
|
|
|
def __getitem__(self, mimetype):
|
|
try:
|
|
return super(Content, self).__getitem__(mimetype)
|
|
except KeyError:
|
|
pass
|
|
|
|
for key, value in iteritems(self):
|
|
if fnmatch.fnmatch(mimetype, key):
|
|
return value
|
|
|
|
raise MimeTypeNotFound(mimetype, self.keys())
|