From e90aecb68fb6cd847e76a85c19f81db0c6bf30f5 Mon Sep 17 00:00:00 2001 From: Stephen Finucane Date: Wed, 15 May 2019 11:12:27 +0100 Subject: [PATCH] Remove use of '__import__' These are not discoverable and, in this particular instance, unnecessary. Change-Id: I43757263ebbb009d10a6023bbd126b41408cbdc0 Signed-off-by: Stephen Finucane --- wsme/rest/protocol.py | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/wsme/rest/protocol.py b/wsme/rest/protocol.py index 1ecf4de..ff53528 100644 --- a/wsme/rest/protocol.py +++ b/wsme/rest/protocol.py @@ -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: