Move around the REST implementation : wsme.protocols.commons -> wsme.rest.args, wsme.protocols.rest -> wsme.rest.protocol, wsme.protocols.restxml/json -> wsme.rest.xml/json, wsme.protocols.__init__ -> wsme.protocol.
--HG-- rename : wsme/protocols/__init__.py => wsme/protocol.py rename : wsme/protocols/commons.py => wsme/rest/args.py rename : wsme/protocols/restjson.py => wsme/rest/json.py rename : wsme/protocols/rest.py => wsme/rest/protocol.py rename : wsme/protocols/restxml.py => wsme/rest/xml.py
This commit is contained in:
parent
4826c8b7ed
commit
ddd2ba251e
@ -30,13 +30,12 @@ classifier =
|
||||
|
||||
[entry_points]
|
||||
wsme.protocols =
|
||||
restjson = wsme.protocols.restjson:RestJsonProtocol
|
||||
restxml = wsme.protocols.restxml:RestXmlProtocol
|
||||
restjson = wsme.rest.json:RestJsonProtocol
|
||||
restxml = wsme.rest.xml:RestXmlProtocol
|
||||
|
||||
[files]
|
||||
packages =
|
||||
wsme
|
||||
wsme.protocols
|
||||
wsme.rest
|
||||
wsme.tests
|
||||
|
||||
|
@ -6,9 +6,9 @@ import json
|
||||
import xml.etree.ElementTree as et
|
||||
|
||||
import wsme
|
||||
import wsme.protocols.commons
|
||||
import wsme.protocols.restjson
|
||||
import wsme.protocols.restxml
|
||||
import wsme.rest.args
|
||||
import wsme.rest.json
|
||||
import wsme.rest.xml
|
||||
|
||||
pecan = sys.modules['pecan']
|
||||
|
||||
@ -18,7 +18,7 @@ class JSonRenderer(object):
|
||||
pass
|
||||
|
||||
def render(self, template_path, namespace):
|
||||
data = wsme.protocols.restjson.tojson(
|
||||
data = wsme.rest.json.tojson(
|
||||
namespace['datatype'],
|
||||
namespace['result']
|
||||
)
|
||||
@ -30,7 +30,7 @@ class XMLRenderer(object):
|
||||
pass
|
||||
|
||||
def render(self, template_path, namespace):
|
||||
data = wsme.protocols.restxml.toxml(
|
||||
data = wsme.rest.xml.toxml(
|
||||
namespace['datatype'],
|
||||
'result',
|
||||
namespace['result']
|
||||
@ -58,7 +58,7 @@ def wsexpose(*args, **kwargs):
|
||||
funcdef = wsme.api.FunctionDefinition.get(f)
|
||||
|
||||
def callfunction(self, *args, **kwargs):
|
||||
args, kwargs = wsme.protocols.commons.get_args(
|
||||
args, kwargs = wsme.rest.args.get_args(
|
||||
funcdef, args, kwargs,
|
||||
pecan.request.body, pecan.request.content_type
|
||||
)
|
||||
|
@ -141,8 +141,8 @@ def args_from_params(funcdef, params):
|
||||
|
||||
|
||||
def args_from_body(funcdef, body, mimetype):
|
||||
from wsme.protocols import restjson
|
||||
from wsme.protocols import restxml
|
||||
from wsme.rest import json as restjson
|
||||
from wsme.rest import xml as restxml
|
||||
|
||||
kw = {}
|
||||
|
@ -1,6 +1,7 @@
|
||||
"""
|
||||
REST+Json protocol implementation.
|
||||
"""
|
||||
from __future__ import absolute_import
|
||||
import datetime
|
||||
import decimal
|
||||
|
||||
@ -8,14 +9,14 @@ import six
|
||||
|
||||
from simplegeneric import generic
|
||||
|
||||
from wsme.protocols.rest import RestProtocol
|
||||
from wsme.rest.protocol import RestProtocol
|
||||
from wsme.types import Unset
|
||||
import wsme.types
|
||||
|
||||
try:
|
||||
import simplejson as json
|
||||
except ImportError:
|
||||
import json
|
||||
import json # noqa
|
||||
|
||||
|
||||
@generic
|
@ -4,8 +4,8 @@ import six
|
||||
from six import u
|
||||
|
||||
from wsme.exc import ClientSideError, UnknownArgument
|
||||
from wsme.protocols import CallContext, Protocol
|
||||
from wsme.protocols.commons import from_params
|
||||
from wsme.protocol import CallContext, Protocol
|
||||
from wsme.rest.args import from_params
|
||||
from wsme.types import Unset
|
||||
|
||||
log = logging.getLogger(__name__)
|
@ -1,3 +1,5 @@
|
||||
from __future__ import absolute_import
|
||||
|
||||
import datetime
|
||||
|
||||
from six import u
|
||||
@ -7,7 +9,7 @@ import xml.etree.ElementTree as et
|
||||
|
||||
from simplegeneric import generic
|
||||
|
||||
from wsme.protocols.rest import RestProtocol
|
||||
from wsme.rest.protocol import RestProtocol
|
||||
import wsme.types
|
||||
|
||||
import re
|
@ -9,7 +9,7 @@ import six
|
||||
import webob
|
||||
|
||||
from wsme.exc import ClientSideError, MissingArgument, UnknownFunction
|
||||
from wsme.protocols import getprotocol
|
||||
from wsme.protocol import getprotocol
|
||||
from wsme.rest import scan_api
|
||||
from wsme import spore
|
||||
import wsme.types
|
||||
|
@ -173,7 +173,7 @@ class TypeDocumenter(autodoc.ClassDocumenter):
|
||||
|
||||
def add_content(self, more_content, no_docstring=False):
|
||||
protocols = self.options.protocols or self.env.app.config.wsme_protocols
|
||||
protocols = [wsme.protocols.getprotocol(p) for p in protocols]
|
||||
protocols = [wsme.protocol.getprotocol(p) for p in protocols]
|
||||
content = []
|
||||
if protocols:
|
||||
sample_obj = make_sample_object(self.object)
|
||||
@ -336,7 +336,7 @@ class FunctionDocumenter(autodoc.MethodDocumenter):
|
||||
found_params = set()
|
||||
|
||||
protocols = self.options.protocols or self.env.app.config.wsme_protocols
|
||||
protocols = [wsme.protocols.getprotocol(p) for p in protocols]
|
||||
protocols = [wsme.protocol.getprotocol(p) for p in protocols]
|
||||
|
||||
for si, docstring in enumerate(docstrings):
|
||||
for i, line in enumerate(docstring):
|
||||
|
@ -3,8 +3,8 @@
|
||||
import unittest
|
||||
|
||||
from wsme import WSRoot
|
||||
from wsme.protocols import getprotocol, CallContext, Protocol
|
||||
import wsme.protocols
|
||||
from wsme.protocol import getprotocol, CallContext, Protocol
|
||||
import wsme.protocol
|
||||
|
||||
|
||||
class DummyProtocol(Protocol):
|
||||
@ -45,8 +45,8 @@ def test_getprotocol():
|
||||
|
||||
class TestProtocols(unittest.TestCase):
|
||||
def test_register_protocol(self):
|
||||
wsme.protocols.register_protocol(DummyProtocol)
|
||||
assert wsme.protocols.registered_protocols['dummy'] == DummyProtocol
|
||||
wsme.protocol.register_protocol(DummyProtocol)
|
||||
assert wsme.protocol.registered_protocols['dummy'] == DummyProtocol
|
||||
|
||||
r = WSRoot()
|
||||
assert len(r.protocols) == 0
|
||||
@ -60,7 +60,7 @@ class TestProtocols(unittest.TestCase):
|
||||
assert r.protocols[0].__class__ == DummyProtocol
|
||||
|
||||
def test_Protocol(self):
|
||||
p = wsme.protocols.Protocol()
|
||||
p = wsme.protocol.Protocol()
|
||||
assert p.iter_calls(None) is None
|
||||
assert p.extract_path(None) is None
|
||||
assert p.read_arguments(None) is None
|
||||
|
@ -3,7 +3,7 @@
|
||||
import datetime
|
||||
import unittest
|
||||
|
||||
from wsme.protocols.commons import from_param, from_params
|
||||
from wsme.rest.args import from_param, from_params
|
||||
|
||||
from wsme.types import UserType, Unset, ArrayType, DictType
|
||||
|
||||
|
@ -9,8 +9,7 @@ try:
|
||||
except:
|
||||
import json # noqa
|
||||
|
||||
import wsme.protocols.restjson
|
||||
from wsme.protocols.restjson import fromjson, tojson
|
||||
from wsme.rest.json import fromjson, tojson
|
||||
from wsme.utils import parse_isodatetime, parse_isotime, parse_isodate
|
||||
from wsme.types import isusertype, register_type
|
||||
from wsme.rest import expose, validate
|
||||
|
@ -9,7 +9,7 @@ import wsme.tests.protocol
|
||||
from wsme.utils import parse_isodatetime, parse_isodate, parse_isotime
|
||||
from wsme.types import isusertype, register_type
|
||||
|
||||
from wsme.protocols.restxml import fromxml, toxml
|
||||
from wsme.rest.xml import fromxml, toxml
|
||||
|
||||
try:
|
||||
import xml.etree.ElementTree as et
|
||||
|
@ -24,9 +24,9 @@ class TestRoot(unittest.TestCase):
|
||||
default_prepare_response_body(None, [u('a'), u('b')]) == u('a\nb')
|
||||
|
||||
def test_protocol_selection_error(self):
|
||||
import wsme.protocols
|
||||
import wsme.protocol
|
||||
|
||||
class P(wsme.protocols.Protocol):
|
||||
class P(wsme.protocol.Protocol):
|
||||
def accept(self, r):
|
||||
raise Exception('test')
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user