Undo rename of 'wsme.rest.json', 'wsme.rest.xml' modules

Use absolute imports to ensure we import the standard library 'json'
module and not our module that shadows it.

Change-Id: I7b55aad974a0145934069f14c91ce03e41bccef3
Signed-off-by: Stephen Finucane <stephenfin@redhat.com>
This commit is contained in:
Stephen Finucane 2019-05-15 11:03:01 +01:00
parent 59d42ef55c
commit 993d8a06d5
9 changed files with 30 additions and 28 deletions

View File

@ -216,8 +216,8 @@ def args_from_params(funcdef, params):
def args_from_body(funcdef, body, mimetype):
from wsme.rest import json_utils as restjson
from wsme.rest import xml_utils as restxml
from wsme.rest import json as restjson
from wsme.rest import xml as restxml
if funcdef.body_type is not None:
datatypes = {funcdef.arguments[-1].name: funcdef.body_type}

View File

@ -1,4 +1,6 @@
"""REST+Json protocol implementation."""
from __future__ import absolute_import
import datetime
import decimal
import json

View File

@ -25,8 +25,8 @@ class RestProtocol(Protocol):
self.content_types = []
for dataformat in dataformats:
__import__('wsme.rest.' + dataformat + '_utils')
dfmod = getattr(wsme.rest, dataformat + '_utils')
__import__('wsme.rest.' + dataformat)
dfmod = getattr(wsme.rest, dataformat)
self.dataformats[dataformat] = dfmod
self.content_types.extend(dfmod.accept_content_types)

View File

@ -7,7 +7,7 @@ from wsme.exc import ClientSideError, InvalidInput
from wsme.types import isarray, isdict, isusertype, register_type
from wsme.types import UserType, ArrayType, DictType
from wsme.rest import expose, validate
from wsme.rest.json_utils import fromjson, tojson, parse
from wsme.rest.json import fromjson, tojson, parse
import wsme.tests.protocol
from wsme.utils import parse_isodatetime, parse_isotime, parse_isodate
@ -563,7 +563,7 @@ class TestRestJson(wsme.tests.protocol.RestOnlyProtocolTestCase):
v.aint = 4
v.astr = 's'
r = wsme.rest.json_utils.encode_sample_value(MyType, v, True)
r = wsme.rest.json.encode_sample_value(MyType, v, True)
print(r)
assert r[0] == ('javascript')
assert r[1] == json.dumps({'aint': 4, 'astr': 's'}, ensure_ascii=False,
@ -574,7 +574,7 @@ class TestRestJson(wsme.tests.protocol.RestOnlyProtocolTestCase):
assert tojson(wsme.types.bytes, b('ascii')) == u('ascii')
def test_encode_sample_params(self):
r = wsme.rest.json_utils.encode_sample_params(
r = wsme.rest.json.encode_sample_params(
[('a', int, 2)], True
)
assert r[0] == 'javascript', r[0]
@ -583,7 +583,7 @@ class TestRestJson(wsme.tests.protocol.RestOnlyProtocolTestCase):
}''', r[1]
def test_encode_sample_result(self):
r = wsme.rest.json_utils.encode_sample_result(
r = wsme.rest.json.encode_sample_result(
int, 2, True
)
assert r[0] == 'javascript', r[0]

View File

@ -5,7 +5,7 @@ import base64
from six import u, b
import six
from wsme.rest.xml_utils import fromxml, toxml
from wsme.rest.xml import fromxml, toxml
import wsme.tests.protocol
from wsme.types import isarray, isdict, isusertype, register_type
from wsme.utils import parse_isodatetime, parse_isodate, parse_isotime
@ -164,7 +164,7 @@ class TestRestXML(wsme.tests.protocol.RestOnlyProtocolTestCase):
value.aint = 5
value.atext = u('test')
language, sample = wsme.rest.xml_utils.encode_sample_value(
language, sample = wsme.rest.xml.encode_sample_value(
MyType, value, True)
print(language, sample)
@ -175,13 +175,13 @@ class TestRestXML(wsme.tests.protocol.RestOnlyProtocolTestCase):
</value>""")
def test_encode_sample_params(self):
lang, content = wsme.rest.xml_utils.encode_sample_params(
lang, content = wsme.rest.xml.encode_sample_params(
[('a', int, 2)], True)
assert lang == 'xml', lang
assert content == b('<parameters>\n <a>2</a>\n</parameters>'), content
def test_encode_sample_result(self):
lang, content = wsme.rest.xml_utils.encode_sample_result(int, 2, True)
lang, content = wsme.rest.xml.encode_sample_result(int, 2, True)
assert lang == 'xml', lang
assert content == b('<result>2</result>'), content

View File

@ -10,17 +10,17 @@ import flask
import wsme
import wsme.api
import wsme.rest.args
import wsme.rest.json_utils
import wsme.rest.xml_utils
import wsme.rest.json
import wsme.rest.xml
from wsme.utils import is_valid_code
log = logging.getLogger(__name__)
TYPES = {
'application/json': wsme.rest.json_utils,
'application/xml': wsme.rest.xml_utils,
'text/xml': wsme.rest.xml_utils,
'application/json': wsme.rest.json,
'application/xml': wsme.rest.xml,
'text/xml': wsme.rest.xml,
}
@ -37,7 +37,7 @@ def get_dataformat():
log.info('Could not determine what format is wanted by the caller, '
'falling back to JSON')
return wsme.rest.json_utils
return wsme.rest.json
def signature(*args, **kw):

View File

@ -8,8 +8,8 @@ import pecan
import wsme
import wsme.rest.args
import wsme.rest.json_utils
import wsme.rest.xml_utils
import wsme.rest.json
import wsme.rest.xml
from wsme.utils import is_valid_code
@ -21,8 +21,8 @@ class JSonRenderer(object):
@staticmethod
def render(template_path, namespace):
if 'faultcode' in namespace:
return wsme.rest.json_utils.encode_error(None, namespace)
return wsme.rest.json_utils.encode_result(
return wsme.rest.json.encode_error(None, namespace)
return wsme.rest.json.encode_result(
namespace['result'],
namespace['datatype']
)
@ -36,8 +36,8 @@ class XMLRenderer(object):
@staticmethod
def render(template_path, namespace):
if 'faultcode' in namespace:
return wsme.rest.xml_utils.encode_error(None, namespace)
return wsme.rest.xml_utils.encode_result(
return wsme.rest.xml.encode_error(None, namespace)
return wsme.rest.xml.encode_result(
namespace['result'],
namespace['datatype']
)

View File

@ -16,8 +16,8 @@ from sphinx.util.docfields import Field
from sphinx.util.nodes import make_refnode
import wsme
import wsme.rest.json_utils
import wsme.rest.xml_utils
import wsme.rest.json
import wsme.rest.xml
import wsme.types
field_re = re.compile(r':(?P<field>\w+)(\s+(?P<name>\w+))?:')
@ -53,10 +53,10 @@ def get_protocols(names):
protocols.extend('restjson', 'restxml')
if 'restjson' in names:
names.remove('restjson')
protocols.append(('Json', wsme.rest.json_utils))
protocols.append(('Json', wsme.rest.json))
if 'restxml' in names:
names.remove('restxml')
protocols.append(('XML', wsme.rest.xml_utils))
protocols.append(('XML', wsme.rest.xml))
for name in names:
p = wsme.protocol.getprotocol(name)
protocols.append((p.displayname or p.name, p))