Merge "Remove use of '__import__'"

This commit is contained in:
Zuul 2020-02-05 07:47:59 +00:00 committed by Gerrit Code Review
commit a274dcada0
1 changed files with 10 additions and 8 deletions

View File

@ -5,7 +5,8 @@ from wsme.utils import OrderedDict
from wsme.protocol import CallContext, Protocol, media_type_accept
import wsme.rest
import wsme.rest.args
from wsme.rest import json
from wsme.rest import xml
import wsme.runtime
log = logging.getLogger(__name__)
@ -14,21 +15,22 @@ log = logging.getLogger(__name__)
class RestProtocol(Protocol):
name = 'rest'
displayname = 'REST'
dataformats = ['json', 'xml']
content_types = ['application/json', 'text/xml']
formatters = {
'json': json,
'xml': xml,
}
def __init__(self, dataformats=None):
if dataformats is None:
dataformats = RestProtocol.dataformats
dataformats = ('json', 'xml')
self.dataformats = OrderedDict()
self.content_types = []
for dataformat in dataformats:
__import__('wsme.rest.' + dataformat)
dfmod = getattr(wsme.rest, dataformat)
self.dataformats[dataformat] = dfmod
self.content_types.extend(dfmod.accept_content_types)
formatter = self.formatters[dataformat]
self.dataformats[dataformat] = formatter
self.content_types.extend(formatter.accept_content_types)
def accept(self, request):
for dataformat in self.dataformats: